fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void fast(){
  5. ios_base::sync_with_stdio(NULL);
  6. cin.tie(0);cout.tie(0);
  7. }
  8. map<int,long long>mpa,mpb;
  9.  
  10. int main(){
  11. fast();
  12. int t=1;
  13. //cin>>t;
  14. while(t--){
  15. int n;
  16. long long s;
  17. cin>>n>>s;
  18. long long arr[n];
  19. for(int i=0;i<n;i++){
  20. cin>>arr[i];
  21. }
  22. int l=0,r=0,mx=0;
  23. long long sum=0;
  24. while(r<n){
  25. sum+=arr[r];
  26. while(sum>s){
  27. sum-=arr[l];
  28. l++;
  29. }
  30. mx=max(mx,r-l+1);
  31. r++;
  32. }
  33. cout<<mx;
  34. }
  35. }
  36.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
21416