#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,X; cin >> N >> X; vectorA(N); vectorB(N+1); for(int i = 0; i < N; i++) { cin >> A[i]; B[i+1] = B[i]+A[i]; } if(B[N] <= X) { cout << B[N] << "\n"; return 0; } long long ans = 0; for(int i = 0; i < N; i++) { int it = upper_bound(B.begin(),B.end(),B[i]+X)-B.begin(); ans = max(ans,B[it-1]-B[i]); it = lower_bound(B.begin(),B.end(),B[N]-(X-B[i]))-B.begin(); if(B[i] <= X) ans = max(ans,B[i]+B[N]-B[it]); } cout << ans << "\n"; }