fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define nmax 1000005
  4. #define mod 1000000007
  5. #define tt ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);
  6. #define co cout<<"Yes";
  7. #define ko cout<<"No";return 0;
  8. #define NAME "QUYLUAT"
  9. using namespace std;
  10. ll n,x;
  11. ll a[nmax];
  12. ll tong=0,dem=0;
  13. int main()
  14. {
  15. tt;
  16. if(fopen(NAME".inp","r"))
  17. {
  18. freopen(NAME".inp","r",stdin);
  19. freopen(NAME".out","w",stdout);
  20. }
  21. cin>>n>>x;
  22. for(int i=1;i<=n;i++)
  23. {
  24. cin>>a[i];
  25. }
  26. int l=1;
  27. for(int r=1;r<=n;r++)
  28. {
  29. tong+=a[r];
  30. while(tong>x)
  31. {
  32. tong-=a[l];
  33. l++;
  34. }
  35. dem+=(r-l+1);
  36. }
  37. cout<<dem;
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty