#pragma GCC optimize ("Ofast") #include using namespace std; inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(long long &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } template inline S chmax(S &a, T b){ if(a= x){ tmp = 0; p++; } if(p >= K){ return 1; } } return 0; } int main(){ int i; int ok; int s = 0; long long res = 0; long long tmp; long long mx; rd(N); rd(K); { int Q5VJL1cS; for(Q5VJL1cS=(0);Q5VJL1cS<(N);Q5VJL1cS++){ rd(A[Q5VJL1cS]); } } for(i=(0);i<(N);i++){ A[i+N] = A[i]; } { int xr20shxY; long long WYIGIcGE; if(N==0){ WYIGIcGE = 0; } else{ WYIGIcGE = A[0]; for(xr20shxY=(1);xr20shxY<(N);xr20shxY++){ WYIGIcGE += A[xr20shxY]; } } mx =WYIGIcGE/ K; } long long ao_dF3pO; long long tU__gIr_; long long a2conNHc; ao_dF3pO = 1; tU__gIr_ = mx; while(ao_dF3pO < tU__gIr_){ if((ao_dF3pO + tU__gIr_)%2==0){ a2conNHc = (ao_dF3pO + tU__gIr_) / 2; } else{ a2conNHc = (ao_dF3pO + tU__gIr_ + 1) / 2; } ok = 0; tmp = 0; for(i=(0);i<(2*N);i++){ tmp += A[i]; if(tmp >= a2conNHc){ tmp = 0; s = i; } } ok |= isok(s+1, a2conNHc); for(i=(0);i<(300);i++){ if(!ok){ ok |= isok(rand()%N, a2conNHc); } } if(ok){ ao_dF3pO = a2conNHc; } else{ tU__gIr_ = a2conNHc - 1; } } chmax(res, tU__gIr_); wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20200813-1 [beta] // --- original code --- // int N, K; ll A[2d5]; // // int isok(int s, ll x){ // int p = 0; // ll tmp = 0; // s %= N; // // rep(i,N){ // tmp += A[i+s]; // if(tmp >= x) tmp = 0, p++; // if(p >= K) return 1; // } // // return 0; // } // // { // int ok, s = 0; // ll res = 0, tmp, mx; // rd(N,K,A(N)); // rep(i,N) A[i+N] = A[i]; // // mx = sum(A(N)) / K; // // res >?= bsearch_max[ll,x,1,mx][ // ok = 0; // tmp = 0; // rep(i,2*N){ // tmp += A[i]; // if(tmp >= x){ // tmp = 0; // s = i; // } // } // ok |= isok(s+1, x); // rep(i,300) if(!ok) ok |= isok(rand()%N, x); // ](ok); // // wt(res); // }