Guest User

CSES 1632

a guest
May 15th, 2020
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <bits//stdc++.h>
  2. #define max(x, y) ((x >= y) ? x: y)
  3. #define min(x, y) ((x <= y) ? x: y)
  4. #define isodd(x) ((x % 2 == 1) ? 1: 0)
  5. #define iseven(x) ((x % 2 == 0) ? 1: 0)
  6. #define forn(i, n) for (long long int i = 0; i < n; i++)
  7. #define forab(i, a, b) for (long long int i = a; i < b; i++)
  8. #define print(x) for (auto i:x) cout << i << ' '; cout << '\n'
  9. #define mp(x, y) make_pair(x, y)
  10. using namespace std;
  11. using lld = signed long long int;
  12.  
  13. int main()
  14. {
  15.     ios_base::sync_with_stdio(false);
  16.     cin.tie(NULL);
  17.     int n, k; cin >> n >> k;
  18.     vector<pair<int, int>> v;
  19.  
  20.     forn (i, n) {
  21.         int x, y; cin >> x >> y;
  22.         v.push_back({y, x});
  23.     }
  24.  
  25.     sort (v.begin(), v.end());
  26.  
  27.     int time[k] = {0};
  28.  
  29.     int cnt = 0;
  30.     multiset <int> p;
  31.  
  32.     forn (i, k) p.insert(0);
  33.  
  34.     for (auto i:v) {
  35.         auto it = p.upper_bound(i.second);
  36.         if (it == p.begin())
  37.             continue;
  38.        
  39.         it--;
  40.         cnt++;
  41.  
  42.         p.erase(it);
  43.         p.insert(i.first);
  44.     }
  45.  
  46.     cout << cnt << "\n";
  47.  
  48.     return 0;
  49. }
  50.  
  51. /*
  52.     author: Ashwin Ginoria
  53.     email: ashwinginoria@gmail.com
  54. */
Add Comment
Please, Sign In to add comment