#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; //yukicoder414C int main() { ll n, x; cin >> n >> x; vector a(2 * n), sum(2 * n + 1); for (int i = 0; i < n; i++) { cin >> a[i]; a[i + n] = a[i]; } sum[1] = a[0]; for (int i = 2; i < 2 * n + 1; i++) { sum[i] = sum[i - 1] + a[i - 1]; } ll mx = 0; ll left = 0; ll right = 1; ll ans = 0; while (right < 2 * n + 1) { ll num = sum[right] - sum[left]; if (num <= x && right - left <= n) { right++; ans = max(ans, num); } else { left++; } } cout << ans << endl; }