#ifdef ONLINE_JUDGE #pragma GCC optimize("Ofast") #pragma GCC target("avx2,bmi,bmi2,lzcnt") #endif #include #include #ifndef DUMP #define DUMP(...) void(0) #endif using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, k; cin >> n >> k; vector pref(2 * n + 1); for (int i = 0; i < n; ++i) { int a; cin >> a; pref[i + 1] = pref[i] + a; } for (int i = n + 1; i <= 2 * n; ++i) pref[i] = pref[i - n] + pref[n]; DUMP(pref); constexpr int lg = 17; auto check = [&](int64_t m) -> bool { vector to(lg, vector(n)); for (int i = 0; i < n; ++i) { to[0][i] = i ? to[0][i - 1] : 0; while (pref[to[0][i]] - pref[i] < m) ++to[0][i]; } for (int s = 1; s < lg; ++s) for (int i = 0; i < n; ++i) { int ni = to[s - 1][i] % n; to[s][i] = to[s - 1][i] + (to[s - 1][ni] - ni); } for (int i = 0; i < n; ++i) { int t = k; int64_t cur = i; for (int s = lg; s--;) { if (t < 1 << s) continue; t -= 1 << s; cur += to[s][cur % n] - cur % n; } if (cur - i <= n) return true; } return false; }; int64_t ok = 1, ng = pref.back() + 1; while (ng - ok > 1) { auto mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } cout << ok << '\n'; }