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