fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define yes cout<<"YES\n";
  6. #define no cout<<"NO\n";
  7. const int N=3e5+7;
  8. ll T = 1, a[N], b[N];
  9. void solve()
  10. {
  11. ll n, m;
  12.  
  13. cin >> n >> m;
  14.  
  15. for(int i = 1; i <= n; i++)
  16. cin >> a[i];
  17.  
  18. ll ans = 0, l = 1;
  19. ll sum = 0;
  20.  
  21. for(int r = 1; r <= n; r++){
  22. sum += a[r];
  23.  
  24. while(l <= r && sum - a[l] >= m)
  25. sum -= a[l], l++;
  26.  
  27. if(sum >= m)
  28. ans += l;
  29. }
  30.  
  31. cout << ans;
  32. }
  33. int main()
  34. {
  35. ios::sync_with_stdio(NULL);
  36. cin.tie(0);
  37. cout.tie(0);
  38.  
  39. // freopen("","r", stdin);
  40. // freopen("","w", stdout);
  41. // cin>>T;
  42. while(T--)
  43. solve();
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 5600KB
stdin
7 20
2 6 4 3 6 8 9
stdout
9