fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4. const int M = 1e9 + 7;
  5.  
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(NULL);
  10.  
  11. int n, t;
  12. cin >> n >> t;
  13. vector<int> v(n + 1);
  14. for (int i = 1; i <= n; i++)
  15. cin >> v[i];
  16. int i = 0, j = 1;
  17. int sum1 = 0, sum2 = 0;
  18. int ans = 0;
  19. while (j <= n)
  20. {
  21. sum1 += v[j];
  22. while (sum1 - 2*sum2 > t)
  23. {
  24. i++;
  25. sum2 += v[i];
  26. }
  27. ans = max(ans, j - i);
  28. j++;
  29. }
  30.  
  31. cout << ans << endl;
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5320KB
stdin
4 5
1 2 3 4
stdout
2