#include #include #include #include #include #include #include #include #include #include #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template void chmin(T &a,const T &b){if(a>b) a=b;} template void chmax(T &a,const T &b){if(a A; const ll INF=1e15; bool judge(ll lim){ int M=A.size(); vector> to(M,vector (20,M)); vector sum(M+1,0); rep(i,M) sum[i+1]=sum[i]+A[i]; int pos=0; for(int i=0;isum[pos]) pos++; to[i][0]=pos; } for(int k=1;k<20;k++) for(int i=0;iN) break; } if(now-i<=N) return true; } return false; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin>>N>>K; A.resize(N); rep(i,N) cin>>A[i]; rep(i,N) A.push_back(A[i]); A.push_back(INF); ll ok=1,ng=INF; while(abs(ok-ng)>1){ ll mid=(ok+ng)/2; if(judge(mid)) ok=mid; else ng=mid; } cout<