fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(NULL);
  7. int n,t;
  8. cin >>n>>t;
  9. vector<int>a(n);
  10. for (int i=0;i< n;i++) cin >>a[i];
  11. int l=0;
  12. long long to=0;
  13. int m=0;
  14. for (int j=0;j<n;j++) {
  15. to+=a[j];
  16. while (to>t) {
  17. to-=a[l];
  18. l++;
  19. }
  20. m=max(m,j-l+1);
  21. }
  22. cout <<m;
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 3.25s 804740KB
stdin
Standard input is empty
stdout
205212448