#include #include using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, X, S = 0, ans, i, j; cin >> N >> X; vector A(N); for (i = 0; i != N; ++i) cin >> A[i]; for (i = 0; i != N && S <= X; ++i) S += A[i]; if (S <= X) { cout << S << '\n'; return 0; } ans = S - A[i - 1]; for (S -= A[0], j = 1; j != N; S -= A[j], ++j) { for (; S <= X; ++i) S += A[i % N]; if (S - A[(i - 1) % N] > ans) ans = S - A[(i - 1) % N]; } cout << ans << '\n'; return 0; }