Advertisement
Ahmed_Negm

F

Apr 14th, 2024
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define nl "\n"
  6.  
  7. void files(){
  8.     ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
  9.     #ifndef ONLINE_JUDGE
  10.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  11.     #endif
  12. }
  13.  
  14.  
  15. void solve(){
  16.     ll n,k; cin>>n>>k;
  17.     vector<ll> v(n);
  18.     for(auto&i:v) cin>>i;
  19.  
  20.     ll ans = n*(n+1)/2;
  21.  
  22.     ll exclude = 0;
  23.  
  24.     ll l=0,r=0, sum = 0;
  25.  
  26.     while(r<n){
  27.         sum += v[r];
  28.         while(sum >= k){
  29.             sum -= v[l];
  30.             l++;
  31.         }
  32.         exclude += r-l+1;
  33.         r++;
  34.     }
  35.  
  36.     cout<<ans-exclude<<nl;
  37.  
  38. }
  39.  
  40. int main(){
  41.     files();
  42.     int t = 1;
  43.     // cin>>t;
  44.     while(t--) solve();
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement