fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define int long long
  4. using namespace std;
  5. const int maxn = 1e6+7;
  6. ll n,k,ans=LLONG_MIN,pre[maxn];
  7. int32_t main()
  8. {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(NULL);
  11. freopen("NGHENHAC.INP","r",stdin);
  12. freopen("NGHENHAC.OUT","w",stdout);
  13.  
  14. cin >> n >> k;
  15. for (int i=1;i<=n;i++)
  16. {
  17. ll x; cin >> x;
  18. pre[i] = pre[i-1] + x;
  19. }
  20.  
  21. ll l=1;
  22. for (int r=1;r<=n;r++)
  23. {
  24. ll sum = pre[r] - pre[l-1];
  25. while (sum > k && l<r)
  26. {
  27. sum -= pre[l];
  28. l++;
  29. }
  30. ans = max(ans,r-l+1);
  31. }
  32. cout << ans;
  33. }
  34.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty