#include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF = 1e18; int N, K; ll A[100005]; ll sum[200005]; ll next_offset[100005][20]; bool used[100005]; void clear_used(){ for(int i = 0; i < N; i++) used[i] = false; } void build(ll m){ for(int i = 0; i < N; i++){ auto p = lower_bound(sum, sum+2*N+2, sum[i]+m); next_offset[i][0] = (p-(sum+i)); } for(int j = 1; j < 18; j++){ for(int i = 0; i < N; i++){ next_offset[i][j] = next_offset[i][j-1]+next_offset[(i+next_offset[i][j-1])%N][j-1]; } } } vector bt; ll cnt(int s){ ll ans = 0; for(int i : bt){ used[s] = true; ans += next_offset[s][i]; s += next_offset[s][i]; s %= N; } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N >> K; for(int i = 0; i < 18; i++){ if(K&(1<> A[i]; sum[i+1] = sum[i]+A[i]; } for(int i = N; i < 2*N; i++){ sum[i+1] = sum[i]+A[i%N]; } sum[2*N+1] = INF; ll l = 1, r = INF/2; while(r-l > 1){ ll c = (l+r)/2; clear_used(); build(c); bool ok = false; for(int i = 0; i < N; i++){ if(!used[i]){ ll tmp = cnt(i); if(tmp <= N) ok = true; } } if(ok) l = c; else r = c; } cout << l << endl; }