/* -*- coding: utf-8 -*- * * 1211.cc: No.1211 円環はお断り - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_N2 = MAX_N * 2; const int BN = 18; const int INF = 1 << 30; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N2], ps[MAX_N2][BN]; /* subroutines */ bool check(int n, int k, int bn, ll m) { int n2 = n * 2; ll sum = 0; for (int i = 0, j = 0; i < n2; i++) { while (j < n2 && sum < m) sum += as[j++]; if (sum < m) ps[i][0] = INF; else ps[i][0] = j; sum -= as[i]; } for (int b = 0; b + 1 < bn; b++) for (int i = 0; i < n2; i++) ps[i][b + 1] = (ps[i][b] < INF) ? ps[ps[i][b]][b] : INF; for (int i = 0; i < n; i++) { int j = i; for (int b = bn - 1; b >= 0 && j < INF; b--) if ((k >> b) & 1) j = ps[j][b]; if (j >= INF) break; if (j - i <= n) return true; } return false; } /* main */ int main() { int n, k; scanf("%d%d", &n, &k); int n2 = n * 2; ll asum = 0; for (int i = 0; i < n; i++) { scanf("%d", as + i), as[n + i] = as[i]; asum += as[i]; } int bn = 0; for (int bi = 1; bi <= n2; bn++, bi <<= 1); //printf("bn=%d\n", bn); ll m0 = 1, m1 = asum + 1; while (m0 + 1 < m1) { ll m = (m0 + m1) / 2; if (check(n, k, bn, m)) m0 = m; else m1 = m; } printf("%lld\n", m0); return 0; }