#include using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << #x << " = " << (x) << endl; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair; using pll = pair; using pdd = pair; template struct V : vector { using vector::vector; }; V() -> V; V(size_t) -> V; template V(size_t, T) -> V; template vector make_vec(size_t n, T a) { return vector(n, a); } template auto make_vec(size_t n, Ts... ts) { return vector(n, make_vec(ts...)); } template ostream& operator << (ostream& os, const pair v){os << "(" << v.first << ", " << v.second << ")"; return os;} template ostream& operator<<(ostream &os, const vector &v) { for (auto &e : v) os << e << ' '; return os; } template ostream& operator<<(ostream& os, const vector> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template void debug(vector>&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cerr<> N >> K; V A(N); REP(i, N) cin >> A[i]; V B(2*N); REP(i, N){ B[i] = A[i]; B[i+N] = A[i]; } // V S(2*N+1, 0); REP(i, 2*N) S[i+1] = S[i] + B[i]; ll ok = 0; ll ng = 1e14; ng++; while(ng-ok>1){ ll D = 17; ll md = (ok+ng)/2; // dump(md) // V next(2*N+2); // REP(i, 2*N){ // ll pos = lower_bound(ALL(S), S[i]+md) - S.begin(); // nex[i] = pos; // } ll idx = 0; REP(i, 2*N){ while(idx<2*N+1 and S[idx]-S[i]> db(2*N+2, V(D, 0)); REP(i, 2*N+2) db[i][0] = nex[i]; REP(j, D-1){ REP(i, 2*N+2){ db[i][j+1] = db[db[i][j]][j]; } } bool kanou = false; REP(i, N){ ll now = i; REP(j, D){ if(K>>j & 1){ now = db[now][j]; } } if(now-i<=N) kanou = true; } // dump(kanou) // cerr << endl; if(kanou) ok = md; else ng = md; } cout << ok << endl; return 0; }