CSES Solutions
#1629Sorting and Searching

Movie Festival

View on CSES

Solution

1629-Movie_Festival.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4signed main(){
5  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
6  int n; cin>>n;
7  pair<int,int>a[n];
8  for(auto&p:a)
9    cin>>p.second>>p.first;
10  sort(a,a+n);
11  int ans=0,p=0,i=0;
12  while(i<n){
13    ++ans,p=a[i++].first;
14    while(i<n&&a[i].second<p) ++i;
15  }
16  cout<<ans<<'\n';
17  return 0;
18}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.