fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. main(){
  5. int n,k;
  6. cin>>n>>k;
  7. vector<int>v(n);
  8. for(auto &it:v)cin>>it;
  9. int sum=0,mx=0;
  10. for(int i=0,j=0;j<n;j++){
  11. sum+=v[j];
  12. while(sum>k){
  13. sum-=v[i];
  14. i++;
  15. }
  16. mx=max(mx,j-i+1);
  17. }
  18. cout<<mx<<"\n";
  19. }
Success #stdin #stdout 0.01s 5316KB
stdin
7 10
8 3 2 1 1 2 2
stdout
5