#include using namespace std; int n, k; vector a; long long solve(); bool ch(long long x); int main() { cin >> n >> k; a.resize(2 * n); for (int i = 0; i < n; ++i) { cin >> a[i]; a[i + n] = a[i]; } cout << solve() << endl; return 0; } long long solve() { long long l = 0, r = 1; for (int i = 0; i < n; ++i) r += a[i]; while (r - l > 1) { long long mid = (l + r) >> 1; if (ch(mid)) l = mid; else r = mid; } return l; } bool ch(long long x) { vector memo(n, -1); for (long long i = 0, sum = 0, r = 0; i < n; ++i) { while (r < 2 * n && sum < x) sum += a[r++]; memo[i] = r - i; sum -= a[i]; } vector> dp; dp.resize(32, vector(n)); dp[0] = memo; for (int i = 1; i <= 30; ++i) for (int j = 0; j < n; ++j) dp[i][j] = dp[i - 1][j] + dp[i - 1][(j + dp[i - 1][j]) % n]; for (int i = 0; i < n; ++i) { long long cnt = 0; for (int j = 0; j <= 30; ++j) if (k >> j & 1) cnt += dp[j][(i + cnt) % n]; if (cnt <= n) return 1; } return 0; }