#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace std::chrono; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase #define REP(i, n) for(int i = 0;i < (n);i++) /*cout<bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;} template bool chmax(T& a,U b){if(a void SO(T& ve){sort(ve.begin(),ve.end());} template void REV(T& ve){reverse(ve.begin(),ve.end());} templatellint LBI(const vector&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();} templatellint UBI(const vector&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();} bool solve(int n,int K,llint S,const vector&wa){ static int go[17][200101]; int h,i,j; for(i=0;i<=n+n;i++){go[0][i]=LBI(wa,wa[i]+S);} go[0][n+n+1]=n+n+1; for(h=1;h<17;h++){ for(i=0;i<=n+n+1;i++){go[h][i]=go[h-1][go[h-1][i]];} } for(i=0;i>n>>K; llint bmax=inf,bmin=0; vectorwa(n+n+1); for(i=1;i<=n;i++){ llint A;cin>>A; wa[i]=wa[i-1]+A; } for(i=n+1;i<=n+n;i++){wa[i]=wa[i-n]+wa[n];} //for(i=0;i1){ llint bgen=(bmax+bmin)/2; if(solve(n,K,bgen,wa)){bmin=bgen;} else{bmax=bgen;} } cout<