Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits//stdc++.h>
- #define max(x, y) ((x >= y) ? x: y)
- #define min(x, y) ((x <= y) ? x: y)
- #define isodd(x) ((x % 2 == 1) ? 1: 0)
- #define iseven(x) ((x % 2 == 0) ? 1: 0)
- #define forn(i, n) for (long long int i = 0; i < n; i++)
- #define forab(i, a, b) for (long long int i = a; i < b; i++)
- #define print(x) for (auto i:x) cout << i << ' '; cout << '\n'
- #define mp(x, y) make_pair(x, y)
- using namespace std;
- using lld = signed long long int;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int n, k; cin >> n >> k;
- vector<pair<int, int>> v;
- forn (i, n) {
- int x, y; cin >> x >> y;
- v.push_back({y, x});
- }
- sort (v.begin(), v.end());
- int time[k] = {0};
- int cnt = 0;
- multiset <int> p;
- forn (i, k) p.insert(0);
- for (auto i:v) {
- auto it = p.upper_bound(i.second);
- if (it == p.begin())
- continue;
- it--;
- cnt++;
- p.erase(it);
- p.insert(i.first);
- }
- cout << cnt << "\n";
- return 0;
- }
- /*
- author: Ashwin Ginoria
- email: ashwinginoria@gmail.com
- */
Add Comment
Please, Sign In to add comment