fork(2) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <iomanip>
  13. #define dibs reserve
  14. #define OVER9000 1234567890
  15. #define patkan 9
  16. #define tisic 47
  17. #define soclose 10e-7
  18. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  19. #define chocolate win
  20. #define ff first
  21. #define ss second
  22. #define abs(x) ((x < 0)?-(x):(x))
  23. // mylittlepony
  24. using namespace std;
  25.  
  26. int main() {
  27. cin.sync_with_stdio(0);
  28. int N;
  29. cin >> N;
  30. int ans =0;
  31. long long t,d, dt =0;
  32. priority_queue<int> q;
  33.  
  34. for(int i =0; i < N; i++) {
  35. cin >> t >> d;
  36. q.push(d);
  37. dt +=d;
  38. while(dt > t) {
  39. dt -=q.top();
  40. ans++;
  41. q.pop();}
  42. }
  43.  
  44. cout << ans << "\n";
  45. return 0;}
  46.  
  47. // look at my code
  48. // my code is amazing
Success #stdin #stdout 0s 3476KB
stdin
5
1 2
3 2
5 3
6 2
7 3
stdout
2