fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define zero cout << 0 << '\n' ;
  4. #define opps cout<<-1<<'\n';
  5. const int MAX = 1e7;
  6. using namespace std;
  7. void solve() {
  8. int n , w ;
  9. cin>>n>>w;
  10. vector<ll> a(n);
  11. for(int i=0;i<n;i++)
  12. cin>>a[i];
  13. ll l = 0 , r = 0 , ans = 0, sumx =0;
  14. while (r < n) {
  15. sumx += a[r];
  16. while (sumx > w && l <= r)
  17. sumx -=a[l++];
  18. r++;
  19. ans = max(ans , sumx);
  20. }
  21. cout<<ans<<'\n' ;
  22. }
  23. int main() {
  24. ios::sync_with_stdio(0);
  25. cin.tie(0);
  26. int t=1;
  27. cin>>t;
  28. while (t--)
  29. solve();
  30. return 0;
  31. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
0