#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define mod 1000000007 using namespace std; typedef pair P; llint n, k; llint a[300005], sum[300005]; llint succ[100005][17]; bool check(llint d) { if(d > sum[n]) return false; llint r = -1; for(int i = 0; i < n; i++){ while(r < i || sum[r]-sum[i] < d) r++; succ[i][0] = r-i;//lower_bound(sum, sum+3*n, sum[i] + d) - (sum+i); } for(int i = 1; i < 17; i++){ for(int j = 0; j < n; j++){ succ[j][i] = succ[j][i-1] + succ[(j+succ[j][i-1])%n][i-1]; } } for(int i = 0; i < n; i++){ llint v = i, s = 0; for(int j = 16; j >= 0; j--){ if(k & (1< n) goto end; v += succ[v][j], v %= n; } } return true; end:; } return false; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = n; i < 3*n; i++) a[i] = a[i%n]; llint s = 0; for(int i = 0; i < 3*n; i++){ sum[i] = s; s += a[i]; } llint ub = 2e14, lb = 0, mid; while(ub-lb>1){ mid = (ub+lb)/2; if(check(mid)) lb = mid; else ub = mid; } cout << lb << endl; return 0; }