Movie Festival - Problem link
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> movies;
while (n--) {
int s, e;
cin >> s >> e;
movies.push_back({s, e});
}
sort(movies.begin(), movies.end(),
[&](const pair<int, int>& a, const pair<int, int>& b) {
if (a.second == b.second)
return a.first < b.first;
return a.second < b.second;
});
int currEnd = -1, count = 0;
for (auto& it : movies) {
if (it.first >= currEnd) {
count++;
currEnd = it.second;
}
}
cout << count << endl;
}
Top comments (0)