/** * author: otera **/ #include using namespace std; #define int long long typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll INF=1LL<<60; #define rep(i, n) for(int i = 0; i < n; ++ i) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i P; typedef pair LP; #define fr first #define sc second #define all(c) c.begin(),c.end() template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } void solve() { int n, k; cin >> n >> k; vector a(3 * n); vector sum(3 * n + 1, 0); rep(i, n) { cin >> a[i]; a[i + 2 * n] = a[i + n] = a[i]; } rep(i, 3 * n) { sum[i + 1] = sum[i] + a[i]; } auto check = [&](ll x) { if(x >= sum[n]) return true; vector> nxt(30, vector(2 * n, 3 * n)); int j = 0; rep(i, 2 * n) { while(sum[j] - sum[i] < x) ++ j; nxt[0][i] = j; } rep(j, 29) { rep(i, n) { nxt[j + 1][i] = (nxt[j][i] >= 2 * n ? 3 * n: nxt[j][nxt[j][i]]); } } rep(i, n) { int s = i; rep(j, 30) { if(k & (1<= 2 * n) return true; s = nxt[j][s]; } } cerr << x << " " << i << " " << s << "\n"; if(s >= i + n) return true; } return false; }; ll ok = INF, ng = 0; while(ok - ng > 1) { ll mid = (ok + ng) / 2; if(check(mid)) ok = mid; else ng = mid; } cout << ok << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(20); //int t; cin >> t; rep(i, t)solve(); solve(); return 0; }