fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27. // 3
  28. // 2 10
  29. // 1 8
  30. // 4 9
  31. // 6 7
  32.  
  33.  
  34.  
  35. vector<vector<int>> a;
  36.  
  37. int consistency(int n, int rate, int capacity){
  38.  
  39. sort(begin(a), end(a));
  40.  
  41. int balance = 0;
  42. int ans = 0;
  43.  
  44. for(int i=0; i<n; i++){
  45. int t = a[i][0];
  46. int pkt = a[i][1];
  47.  
  48. if(i-1>=0){
  49. int lastT = a[i-1][0];
  50. int timeDif = t-lastT;
  51.  
  52. balance = max(0LL, balance - rate*timeDif);
  53. }
  54.  
  55. balance += pkt;
  56.  
  57. if(balance > capacity){
  58. ans += balance - capacity;
  59. balance = capacity;
  60. }
  61.  
  62.  
  63. }
  64.  
  65. return ans;
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. int practice(int n, int rate, int capacity){
  83.  
  84.  
  85. return 0;
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92. void solve() {
  93.  
  94. int n;
  95. cin>> n;
  96. int capacity, rate;
  97. cin >> rate >> capacity;
  98.  
  99. a.resize(n);
  100. for(int i=0; i<n; i++){
  101. int x, y;
  102. cin >> x >> y;
  103. a[i] = {x, y};
  104. }
  105.  
  106. cout << consistency(n, rate, capacity) << endl;
  107.  
  108.  
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115. int32_t main() {
  116. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  117.  
  118. int t = 1;
  119. // cin >> t;
  120. while (t--) {
  121. solve();
  122. }
  123.  
  124. return 0;
  125. }
Success #stdin #stdout 0s 5324KB
stdin
3
2 10
1 8
4 9
6 7
stdout
4