#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n, x; cin >> n >> x; vector a(n); rep(i, n) cin >> a[i]; vector sum(2 * n + 1, 0); rep(i, 2 * n) sum[i + 1] = sum[i] + a[i % n]; ll ans = 0; rep(i, n) { auto it = upper_bound(sum.begin() + i, sum.begin() + i + n + 1, sum[i] + x) - 1; ans = max(ans, *it - sum[i]); } cout << ans << endl; return 0; }