#include #include using namespace std; long long N, K; long long A[1 << 18], B[1 << 18]; long long par[1 << 18][22]; bool solve(long long border) { for (int i = 0; i <= 2 * N; i++) { int pos1 = lower_bound(B, B + 2 * N, B[i] + border) - B; par[i][0] = pos1; } for (int i = 0; i <= 20; i++) { for (int j = 0; j <= 2 * N; j++) par[j][i + 1] = par[par[j][i]][i]; } for (int i = 0; i < N; i++) { int cx = i; for (int j = 20; j >= 0; j--) { if ((K / (1LL << j)) % 2 == 1) cx = par[cx][j]; } if (cx <= i + N) return true; } return false; } int main() { cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = N; i <= 2 * N; i++) A[i] = A[i - N]; for (int i = 0; i <= 2 * N; i++) B[i + 1] = B[i] + A[i]; long long cl = 0, cr = (1LL << 50), cm, maxn = 0; for (int i = 0; i < 53; i++) { cm = (cl + cr) / 2LL; bool I = solve(cm); if (I == true) { maxn = max(maxn, cm); cl = cm; } else { cr = cm; } } cout << maxn << endl; return 0; }