#include #include using namespace std; long long N, K; long long A[1 << 18], B[1 << 18]; long long par[1 << 18][22]; long long maxval = 0; bool used[22]; bool solve(long long border) { int pos1 = 0; for (int i = 0; i <= 2 * N; i++) { while (pos1 < 2 * N && B[i] + border > B[pos1]) pos1++; par[i][0] = pos1; } for (int i = 0; i < maxval; 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 = maxval; j >= 0; j--) { if (used[j] == true) 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]; for (int i = 0; i < 22; i++) { if ((K / (1LL << i)) % 2 == 1) { used[i] = true; maxval = i; } } long long cl = 0, cr = B[N] / K, cm, maxn = 0, cnt = 0; for (int i = 0; i < 53; i++) { if (cr - cl <= 2) cnt++; if (cnt >= 4) break; 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; }