fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. int main() {
  7. // your code goes here
  8. ll n;
  9. cin>>n;
  10. ll b[n];
  11. for(int i = 0; i < n; i++){
  12. cin>>b[i];
  13. }
  14. ll k;
  15. cin>> k;
  16. ll count = 0,sum=0;
  17. for(int i = 0,j=0; j < n; j++){
  18. sum += b[j];
  19. while(sum > k){
  20. sum -= b[i];
  21. i++;
  22. }
  23. count += (j - i + 1);
  24. }
  25. cout<<count<<endl;
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5292KB
stdin
6

2 1 1 8 2 2

4
stdout
9