another 4 sorting and searching problems
This commit is contained in:
28
CSES - CSES Problem Set/Movie_Festival.cpp
Normal file
28
CSES - CSES Problem Set/Movie_Festival.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// Movie Festival
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
int n; cin >> n;
|
||||
vector<pair<ll, ll>> movies(n);
|
||||
for (auto &p: movies) {
|
||||
ll a, b; cin >> a >> b;
|
||||
p = {b, a};
|
||||
}
|
||||
int count = 0;
|
||||
int current_time = 0;
|
||||
std::sort(movies.begin(), movies.end());
|
||||
for (auto &[end, start]: movies) {
|
||||
if (start >= current_time) {
|
||||
current_time = end;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << count << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user