fork download
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. int main(void){
  5. int n;
  6. cin>> n;
  7. vector<int> arr(n);
  8. //take the input from the user
  9. for(int i=0;i<n;i++){
  10. cin>>arr[i];
  11. }
  12. int sum;
  13. int count=0;
  14. int k;
  15. cin>>k;
  16. for(int i=0;i<n;i++){
  17. sum=0;
  18. for(int j=i;j<n;j++){
  19. sum+=arr[j];
  20. if(sum<k){
  21. count++;
  22. }
  23. }
  24. }
  25. cout<<count;
  26. return 0;
  27. }
  28.  
  29.  
Success #stdin #stdout 0s 5328KB
stdin
15 
1 2 3 5 8 8 8 8 2 1 1 1 1 1 1 
4
stdout
21