#include using namespace std; int main() { int N, K; cin >> N >> K; vector A(2*N+1); int sum_A = 0; for (int i = 1; i < N+1; i++) { cin >> A[i]; A[i+N]=A[i]; sum_A += A[i]; } for (int i = 1; i < 2*N+1; i++) { A[i] += A[i-1]; } int ok = 0, ng = sum_A / K+1; while (abs(ok-ng) > 1) { int mid = (ok+ng) / 2; vector perm(2*N+1); for (int i = 0; i < 2*N+1; i++) { perm[i] = i; } int r = 0; for (int l = 0; l < 2*N; l++) { while (r < 2*N && A[r]-A[l] < mid) { r++; } perm[l] = r; } int k = log2(K) + 1; vector> perm_doub(2*N+1, vector(k)); for (int n = 0; n < 2*N+1; n++) { perm_doub[n][0] = perm[n]; } for (int kk = 1; kk < k; kk++) { for (int n = 0; n < 2*N+1; n++) { perm_doub[n][kk] = perm_doub[perm_doub[n][kk-1]][kk-1]; } } bool found = false; for (int i = 0; i < N; i++) { int x = i; for (int kk = 0; kk < k; kk++) { if (K>>kk & 1) { x = perm_doub[x][kk]; } } if (mid < A[i]) { break; } if (i + 1 <= x && x <= i + N) { found = true; break; } } if(found){ ok=mid; } else{ ng = mid; } } cout << ok << endl; return 0; }