generated from projeto-de-algoritmos/RepositorioTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
102961zh.cpp
32 lines (29 loc) · 877 Bytes
/
102961zh.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
* Autor: Matheus Oliveira
* Link do Problema: https://codeforces.com/gym/102961/problem/ZH
* Nível: Intermediário Baixo
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k; cin >> n >> k;
vector<pair<int, int>> movies(n);
for (int i = 0; i < n; ++i) {
cin >> movies[i].second >> movies[i].first;
}
sort(movies.begin(), movies.end());
multiset<int> candidates;
for (int i = 0; i < k; ++i) candidates.insert(0);
int ans = 0;
for (int i = 0; i < n; i++) {
auto greater = candidates.upper_bound(movies[i].second);
if (greater == candidates.begin()) continue;
--greater;
candidates.erase(greater);
candidates.insert(movies[i].first);
// movies.erase(movies.begin() + i);
++ans;
}
// cout << n - movies.size() << endl;
cout << ans << '\n';
}