#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<inline bool chmax(T &a,const T &b){if(ainline bool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const pair&p){ os< ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,pair&p){ is>>p.first>>p.second; return is; } template istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } const int SZ=19; signed main(){ int n,k;cin>>n>>k; vector a(n); cin>>a; vector sum(1,0); rep(i,n)sum.push_back(sum.back()+a[i]); rep(i,n)sum.push_back(sum.back()+a[i]); ll d[n][SZ+1]; auto check=[&](ll m){ if(sum[n]=m){ res=mid; hi=mid-1; }else{ lw=mid+1; } } d[i][0]=res; } rep(j,SZ){ rep(i,n){ int nxt=(i+d[i][j])%n; d[i][j+1]=d[i][j]+d[nxt][j]; } } ll mi=LINF; rep(i,n){ ll cnt=0;int p=i; for(int j=0;j<20;j++){ if((k>>j)&1){ cnt+=d[p][j]; p=(p+d[p][j])%n; } } chmin(mi,cnt); } return mi<=n; }; ll lw=*min_element(ALL(a)),hi=100000050000000,res=-1; while(lw<=hi){ ll mid=(lw+hi)/2; if(check(mid)){ res=mid; lw=mid+1; }else{ hi=mid-1; } } cout<