fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. long long n , x , a[10000],s=0,d=0;
  6. cin>>n>>x;
  7. for ( int i=0 ; i<n;i++)
  8. {
  9.  
  10. cin>>a[i];
  11.  
  12. }
  13. long long slow=0;
  14. for ( long long fast=1 ; fast < n ; fast++ )
  15. {
  16. s+=a[fast];
  17. while ( a[fast] + a[slow] > x && slow <= fast)
  18. {
  19. s-=a[slow];
  20. slow++;
  21. }
  22. if ( s <= x )
  23. {
  24. d=max(d , fast-slow+1);
  25. }
  26. }
  27. cout<<d;
  28. return 0;
  29.  
  30. }
Success #stdin #stdout 0s 5288KB
stdin
10 3
0 0 1 1 1 2 2 3 3 4
stdout
5