CSES Restaurant Customers

Hello , i am doing cses problem set question Restaurant Customers
here is the link to the question CSES - Restaurant Customers
here is my code

if name == ‘main’:
d = []
n = int(input())
lis = []

for i in range(n):
    x,y =  map(int,input().split())
    if x == 35484384:
        flag = 1
    lis.append((x,1))
    lis.append((y,-1))
 

lis2 = sorted(lis,key=lambda  x:x[0])
count = 0
mx  = 0
for i in lis2:
    count += i[1]
    mx = max(mx,count)
    
print(mx)

my code fails at this particular case
200000
35484384 332345209
859511920 894165092
893712826 960478308
358444631 882489895

times out to be precise . please help me come up with a more time efficient code .

use vector for this will be easier , pb {x,1} , {y,-1} then sort it
#include<bits/stdc++.h>
#include
#include
#include<stdio.h>
#define vi vector
#define pb push_back
#define ll long long
using namespace std;
vi<pair<ll,ll>>a ;
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0) ;
cout.tie(0) ;
ll n ;
cin >> n ;
ll x , y ;
for (int i=1;i<=n;i++){
cin>>x>>y;
a.pb({x,1}) ;
a.pb({y,-1}) ;
}
ll ans = 0 , sum = 0 ;
sort(a.begin(),a.end());
for (int i=0;i<a.size();i++){
sum +=a[i].second ;
ans = max(sum,ans);
}
cout << ans ;
}