Advertisement
Dmaxiya

训练士兵 参考代码

Mar 27th, 2025
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 1000000 + 100;
  6. int n;
  7. LL s, p, c, ans;
  8. LL sum[maxn];
  9.  
  10. int main() {
  11. #ifdef ExRoc
  12.     freopen("test.txt", "r", stdin);
  13. #endif // ExRoc
  14.     ios::sync_with_stdio(false);
  15.  
  16.     cin >> n >> s;
  17.     for (int i = 1; i <= n; ++i) {
  18.         cin >> p >> c;
  19.         sum[1] += p;
  20.         sum[c + 1] -= p;
  21.     }
  22.     for (int i = 1; i < maxn; ++i) {
  23.         sum[i] += sum[i - 1];
  24.         ans += min(sum[i], s);
  25.     }
  26.     cout << ans << endl;
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement