Salvens

B

Aug 7th, 2023
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. #define int long long
  7.  
  8. const long long INF = 1e9 + 7;
  9. const int MAXN = 200 + 10;
  10. const int N = 1e5 + 10;
  11.  
  12. int Sum(int a1, int n, int d) {
  13.     return (2 * a1 + d * (n - 1)) * n / 2;
  14. }
  15.  
  16. signed main() {
  17.     ios_base::sync_with_stdio(false);
  18.     cin.tie(nullptr);
  19.     cout.tie(nullptr);
  20.  
  21.     int n, s;
  22.     cin >> n >> s;
  23.     vector<int> a(n);
  24.     for (int i = 0; i < n; ++i) {
  25.         cin >> a[i];
  26.     }
  27.     int l = 0, sum = 0, ans = 0;
  28.     for (int r = 0; r < n; ++r) {
  29.         sum += a[r];
  30.         while (sum > s && l <= r) {
  31.             sum -= a[l];
  32.             ++l;
  33.         }
  34.         ans += Sum(1, r - l + 1, 1);
  35.     }
  36.     cout << ans << '\n';
  37. }
Advertisement
Add Comment
Please, Sign In to add comment