Problem:
The Maximum Number of Customers
$N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours.
Constraints
$ 1 \leq N \leq 10^5 $
$ 1 \leq T \leq 10^5 $
$ 0 \leq l_i < r_i \leq T $
Input
The input is given in the following format.
$N$ $T$
$l_1$ $r_1$
$l_2$ $r_2$
:
$l_N$ $r_N$
Output
Print the maximum number of persons in a line.
Sample Input 1
6 10
0 2
1 3
2 6
3 8
4 10
5 10
Sample Output 1
4
Sample Input 2
2 2
0 1
1 2
Sample Output 2
1

Submitted solutions:

code_snippet: #define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define OVERLOAD_REP(v1, v2, v3, v4, NAME, ...) NAME
#define REP1(i, n) for (int i = 0; (i) < (n); ++(i))
#define REP2(i, l, r) for (int i = (l); (i) < (r); ++(i))
#define REP3(i, l, r, d) for (int i = (l); (i) < (r); (i)+=(d))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)
#define OVERLOAD_PRE(v1, v2, v3, v4, NAME, ...) NAME
#define PRE1(i, n) for (int i = (n)-1; (i) >= 0; --(i)) // [0,n)
#define PRE2(i, l, r) for (int i = (r)-1; (i) >= (l); --(i)) //[l,r)
#define PRE3(i, l, r, d) for (int i = (r)-1; (i) >= (l); (i)-=(d))
#define pre(...) OVERLOAD_PRE(__VA_ARGS__, PRE3, PRE2, PRE1)(__VA_ARGS__)
#define bg begin()
#define en end()
#define rbg rbegin()
#define ren rend()
#define all(x) x.bg,x.en
#define rall(x) x.rbg,x.ren
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fir first
#define sec second
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using sti = stack<int>;
using sei = set<int>;
using qi = queue<int>;
using qii = queue<pii>;
using dqi = deque<int>;
template<class t, class s> using umap = unordered_map<t,s>;
template<class t> using uset = unordered_set<t>;
template<class t> using mset = multiset<t>;
template<class t> using pq=priority_queue<t>;
template<class t> using pqg=priority_queue<t,vector<t>, greater<t>>;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
template<class t> using vvvc=vc<vc<vc<t>>>;
using vi=vc<int>;
using vvi=vc<vc<int>>;
using vll=vc<ll>;
using vvll=vc<vc<ll>>;
using vd=vc<double>;
using vvd=vc<vc<double>>;
using vb=vc<bool>;
using vvb=vc<vc<bool>>;
using vch=vc<char>;
using vs=vc<string>;
const int inf = 1001001001;
const ll infl = 1LL << 60;
const ll mod = 998244353;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
void yes(){ cout << "Yes" << '\n'; }
void no(){ cout << "No" << '\n'; }

int main() {
    ios::sync_with_stdio(false);
  	cin.tie(0);
    int n,t; cin >> n >> t;
    vi sum(t+1);
    rep(i,n){
        int l,r; cin >> l >> r;
        sum[l]++; sum[r]--;
    }
    rep(i,t)sum[i+1]+=sum[i];
    cout << *max_element(all(sum)) << "\n";
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3560
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; ++i)
using ll = long long;

int N, T;
int c[100001];

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N, T;
    cin >> N >> T;
    
    rep(i,N) {
        int l, r;
        cin >> l >> r;
        ++c[l], --c[r];
    }
    
    int ans = 0, now = 0;
    rep(i,T) {
        now += c[i];
        if(ans < now) ans = now;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3840
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; ++i)
using ll = long long;

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N, T;
    cin >> N >> T;
    
    vector<int> c(T + 1, 0);
    rep(i,N) {
        int l, r;
        cin >> l >> r;
        
        ++c[l], --c[r];
    }
    
    rep(i,T) c[i + 1] += c[i];
    
    int ans = 0;
    rep(i,T + 1) ans = max(ans, c[i]);
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3608
final_rank: 3

code_snippet: #include<bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define endl '\n'
#define MAX

typedef long long ll;
typedef pair<int,int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n,t;
	cin >> n >> t;
	vector<pii> events;
	for(int i = 0; i < n; i++){
	    int l,r;
	    cin >> l >> r;
	    events.push_back({l,1});
	    events.push_back({r,-1});
	}
	sort(events.begin(),events.end());
	int people = 0;
	int solve = 0;
	for(int i = 0; i < events.size();i++){
	    people += events[i].second;
	    solve = max(solve,people);
	}

    cout << solve << endl;
	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5200
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define ll long long 
#define N 100100

ll mid(ll l ,ll r){
    return (l+r)/2;
}

ll t[4*N];

void build(ll ind ,ll l, ll r){
    if(l==r){
        t[ind] = 0;
        return;
    }
    ll m = mid(l,r);
    build(2*ind,l,m);
    build(2*ind+1,m+1,r);
    t[ind] = 0;
}

void update(ll ind , ll l ,ll r, ll pos , ll x){
    if(pos<l or pos>r)return;
    if(l==r){
        t[ind]+=x;
        return;
    }
    ll m = mid(l,r);
    if(m>=pos)update(2*ind,l,m,pos,x);
    else update(2*ind+1,m+1,r,pos,x);
    t[ind] = t[2*ind] + t[2*ind+1];
}

ll sum(ll ind , ll l , ll r , ll ql , ll qr){
    if(r<ql or l>qr)return 0;
    if(l>=ql and r<=qr)return t[ind];
    ll m = mid(l,r);
    return sum(2*ind,l,m,ql,qr) + sum(2*ind+1,m+1,r,ql,qr);
}

void solve(){

    ll n,t;
    cin>>n>>t;

    // build(1,1,N);

    for(ll i=0;i<n;i++){
        ll l,r;
        cin>>l>>r;
        l++ , r++;
        update(1,1,N,l,1);
        update(1,1,N,r,-1);
    }
    ll ans = 0;
    for(ll i=1;i<N;i++){
        ans = max(ans,sum(1,1,N,1,i));
    }

    cout<<ans<<endl;
     
}
 
int main(){
    int t =1;
    // cin>>t;
    while(t--)solve();
}
accuracy: 1
time_ms: 50
memory_kb: 5448
final_rank: 14

code_snippet: #include <iostream>
#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 1000010
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define ALL(x)  x.begin(), x.end()
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, n1, t; cin >> n >> t;
    vi start, ended;
    vii intervals;
    n1 = n;
    while (n1--){
        int l, r; cin >> l >> r;
        intervals.emplace_back(l, r);
        start.push_back(l);
        ended.push_back(r);
    }
    sort(ALL(start));
    sort(ALL(ended));
    int max = -MAXN;
    for (int i = 1; i < t; ++i) {
        auto it = lower_bound(ALL(ended), i);
        auto it1 = lower_bound(ALL(start),i);
        int cant = it - ended.begin();
        int cant1 = start.end() - it1;
        int sum =  n - cant - cant1;
        if(sum > max) {
            max = sum;
        }
    }
    cout << max << endl;
    return 0;
}
accuracy: 0.8461538461538461
time_ms: 20
memory_kb: 5048
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll n, t;
    cin >> n >> t;
    vector<ll> vec(t+2,0);
    for (ll i = 0; i < n; i++) {
        ll l, r;
        cin >> l >> r;
        vec[l]++;
        vec[r]--;
    }

    ll ans = vec[0];
    for (ll i = 1; i < t+2; i++) {
        vec[i] = vec[i] + vec[i-1];
        ans = max(ans, vec[i]);
    }

    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3900
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll n, t;
    cin >> n >> t;
    vector<ll> vec(t+2,0);
    for (ll i = 0; i < n; i++) {
        ll l, r;
        cin >> l >> r;
        vec[l]++;
        vec[r]--;
    }

    ll ans = 0;
    for (ll i = 1; i < t+2; i++) {
        vec[i] = vec[i] + vec[i-1];
        ans = max(ans, vec[i]);
    }

    cout << ans << endl;
    return 0;
}
accuracy: 0.8461538461538461
time_ms: 30
memory_kb: 3864
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n, t;
    cin >> n >> t;
    vector<int> vec(t+2,0);
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        vec[l]++;
        vec[r]--;
    }

    int ans = 0;
    for (int i = 1; i < t+2; i++) {
        vec[i] = vec[i] + vec[i-1];
        ans = max(ans, vec[i]);
    }

    cout << ans << endl;
    return 0;
}
accuracy: 0.8461538461538461
time_ms: 30
memory_kb: 3636
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
	int N,T;cin>>N>>T;
	vector<int>cnt(T+2,0);
	for(int i=0;i<N;i++){
		int l,r;cin>>l>>r;
		cnt[l]++,cnt[r]--;
	}
	int ans=0;
	for(int i=0;i<=T;i++){
		cnt[i+1]+=cnt[i];
		ans=max(ans,cnt[i]);
	}
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3712
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
	int N,T;cin>>N>>T;
	vector<int>cnt(T+2,0);
	for(int i=0;i<N;i++){
		int l,r;cin>>l>>r;
		cnt[l]++,cnt[r]--;
	}
	int ans=0;
	for(int i=0;i<T;i++){
		cnt[i+1]+=cnt[i];
		ans=max(ans,cnt[i+1]);
	}
	cout<<ans<<endl;
}
accuracy: 0.8461538461538461
time_ms: 20
memory_kb: 3712
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5, MOD = 1e9 + 7;

int ps[N];

int main(){
    ios::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);

    // freopen(taskname".inp", "r", stdin);
    // freopen(taskname".out", "w", stdout);

    int n, t;
    cin >> n >> t;

    for (int i = 1; i <= n; i++){
        int x, y;
        cin >> x >> y;

        ps[x]++;
        ps[y]--;
    }

    int maxi = 0;
    for (int i = 0; i <= t; i++){
        ps[i] += ps[i - 1];
        maxi = max(maxi, ps[i]);
    }

    cout << maxi << '\n';

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3764
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n,t;
	cin>>n>>t;
	vector<int>s(t+2);
	for(int i=0;i<n;i++){
		int l,r;
		cin>>l>>r;
		s[l]++;
		s[r]--;
	}
	for(int i=0;i<=t;i++)s[i+1]+=s[i];
	cout<<*max_element(s.begin(),s.end())<<'\n';
}
accuracy: 1
time_ms: 30
memory_kb: 3628
final_rank: 9

code_snippet: #include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;

typedef long long ll;

struct LongImos {
    ll n;
    map<ll, ll> ma;
    vector<ll> li, ri, sum;

    LongImos() { ma[inf()] = 0; }
    ll inf() { return 2e18; }
    void add(ll l, ll r, ll c) {
        // [l, r] <- +c
        ma[l] += c;
        ma[r + 1] -= c;
    }
    void make() {
        li = vector<ll>(0);
        ri = vector<ll>(0);
        sum = vector<ll>(0);
        ll nowt = -inf(), nowc = 0;
        for (auto p : ma) {
            auto key = p.first;
            auto val = p.second;
            li.push_back(nowt);
            ri.push_back(key - 1);
            sum.push_back(nowc);
            nowt = key;
            nowc += val;
        }
    }
};

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int n, t;
    cin >> n >> t;
    LongImos imos;
    rep(i, 0, n) {
        ll l, r;
        cin >> l >> r;
        imos.add(l, r - 1, 1);
    }
    int ans = 0;
    imos.make();
    rep(i, 0, imos.li.size()) { ans = max(ans, (int)imos.sum[i]); }
    cout << ans << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 6400
final_rank: 12

code_snippet: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n,m) for(int i=(int)(n);i < (int)(m); i++)
#define repm(i,n,m) for(int i=(int)(n);i >= (int)(m); i--)
// #define _GLIBCXX_DEBUG
using namespace std;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n,t;
    cin >> n >> t;
    vector<int> A(t,0);
    int left, right;
    rep(i,0,n){
        cin >> left >> right;
        A[left]++;
        if(right < t) A[right]--;
    }
    int ans = A[0];
    rep(i,1,t){
        A[i] += A[i-1];
        ans = max(ans, A[i]);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3600
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    int N,T;
    cin>>N>>T;
    vector<int>l(N);
    vector<int>r(N);
    vector<int>d(T);
    vector<int>A(10000000);
    for(int i=0;i<N;i++){
        cin>>l[i]>>r[i];
     
        d[l[i]]++;
        d[r[i]]--;
        
    }
    A[-1]=0;
    for(int i=0;i<T;i++){
        A[i]=A[i-1]+d[i];
    }
    int m=0;
    for(int i=0;i<T;i++){
     //   cout<<A[i]<<endl;
        m=max(m,A[i]);
    }
   cout<<m<<endl;
}


 // g++ a.cpp -o a
accuracy: 1
time_ms: 30
memory_kb: 43340
final_rank: 16

code_snippet: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n,m) for(int i=(int)(n);i < (int)(m); i++)
#define repm(i,n,m) for(int i=(int)(n);i >= (int)(m); i--)
// #define _GLIBCXX_DEBUG
using namespace std;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n,t;
    cin >> n >> t;
    vector<int> L(n),R(n),table(t,0);
    rep(i,0,n) cin >> L[i] >> R[i];
    rep(i,0,n){
        table[L[i]]++;
        table[R[i]]--;
    }
    rep(i,1,t){
        table[i] += table[i-1];
    }
    int ans = 0;
    rep(i,0,t){
        ans = max(ans, table[i]);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4396
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n,m) for(int i=(int)(n);i < (int)(m); i++)
#define repm(i,n,m) for(int i=(int)(n);i >= (int)(m); i--)
// #define _GLIBCXX_DEBUG
using namespace std;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n,t;
    cin >> n >> t;
    vector<pair<int,int>> LR(2*n);
    rep(i,0,n){
        cin >> LR[i].first >> LR[n+i].first;
        LR[i].second = 1;
        LR[n+i].second = -1;
    }
    sort(LR.begin(),LR.end());
    int cnt = 0, ans = 0;
    rep(i,0,2*n){
        cnt += LR[i].second;
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 4668
final_rank: 8

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<deque>
#include<list>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ld EPS = 1e-10;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const ld PI = acos( -1.0 );

#define SWAP( A, B ) { auto tmp = A; A = B; B = tmp; }

template <typename T>
void print( vector<T> v ){
    if( v.size() == 0 ) return;
    for( int i = 0 ; i < v.size() - 1 ; i++ )
        cout << v[i] << ' ';
    cout << v[v.size()-1] << endl;
}

ll max_customer( ll T, const vector<P> &time ){

    ll res = 0, s = 0;
    vector<ll> sum;

    for( int i = 0 ; i < T ; i++ )
        sum.push_back( 0 );
    for( int i = 0 ; i < time.size() ; i++ ){
        sum[time[i].first]++;
        sum[time[i].second]--;
    }
    for( int i = 0 ; i < T ; i++ ){
        s += sum[i];
        res = max( res, s );
    }
    return res;

}

int main(){

    int N;
    ll T, l, r;
    vector<P> time;

    cin >> N >> T;
    for( int i = 0 ; i < N ; i++ ){
        cin >> l >> r;
        time.push_back( make_pair( l, r ) );
    }
    cout << max_customer( T, time ) << endl;

}
accuracy: 1
time_ms: 30
memory_kb: 6512
final_rank: 13

code_snippet: #include <stdio.h>
#define TMAX 100001
#define THALF 50000

void fill(int *p, int T, int d)
{
	int i;
	for(i=0; i<T; i++){
		*(p+i) = d;
	}
}
void stak(int *p, int head, int end, int d)
{
	int i;
	for(i=head; i<end; i++){
		*(p+i) += d;
	}
}

int main(void)
{
    int N, T, t[TMAX], in, out, d, sw, max=0, i, j;
    scanf("%d%d", &N, &T);
	scanf("%d%d", &in, &out);
	sw = (THALF > out - in ? 1 : 2);
	switch(sw){
		case 1:
			fill(t, T, 0);
			stak(t, in, out, 1);
			for(i=1; i<N; i++){
				scanf("%d%d", &in, &out);
				stak(t, in, out, 1);
    		}
		    for(j=0; j<T; j++){
		        max = (max < *(t+j) ? *(t+j) : max);
		    }
			break;
		case 2:
			fill(t, T, N);
			stak(t, 0, in, -1);
			stak(t, out, T, -1);
			for(i=1; i<N; i++){
				scanf("%d%d", &in, &out);
				stak(t, 0, in, -1);
				stak(t, out, T, -1);
			}
			for(j=0; j<T; j++){
				max = (max < *(t+j) ? *(t+j) : max);
			}
			break;
		default:
			break;
	}
    printf("%d\n", max);
    return 0;
}
accuracy: 1
time_ms: 340
memory_kb: 3360
final_rank: 15