#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair LP; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; int n,k; ll a[100010]; vector S; bool check(ll x){ vector> table(2*n+2,vector(18,0)); rep(i,2*n+1){ table[i][0]=lower_bound(S.begin(),S.end(),x+S[i])-S.begin(); //cout << i << " " << table[i][0] << endl; } rep(j,18){ table[2*n+1][j]=2*n+1; } rep(j,17){ rep(i,2*n+1){ table[i][j+1]=table[table[i][j]][j]; } } rep(i,n){ int pos=i; rep(j,17){ if(k&(1 << j)) pos=table[pos][j]; } if(pos<=i+n){ return true; } } return false; } void solve(){ cin >> n >> k; rep(i,n) cin >> a[i]; S.resize(2*n+2); rep(i,n){ S[i+1]=S[i]+a[i]; } rep(i,n){ S[i+n+1]=S[i+n]+a[i]; } S[2*n+1]=INF; ll l=0,r=INF; while(r-l>1){ ll mid=(l+r)/2; if(check(mid)) l=mid; else r=mid; } cout << l << endl; return; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }