// The value of a [I] for the maximum and minimum // days is fixed and cannot be changed. # include <algorithm> # include <string. h> # include <stdio. h> using namespace STD; int n, m; int A [100010]; int judge (int x) {int ans = 1; // It is divided into several groups of int TMP = 0; for (INT I = 0; I <n; I ++) {TMP + = A [I]; If (TMP> X) {TMP = A [I]; // The previous I-1 days less than or equal to m, the previous I-1 days as a group, the day I as the next Group of the first day ans ++ ;}} if (ANS> m) // if the value is greater than m, mid is too small. Return false; return true;} int main () {int I, sum, low; while (~ Scanf ("% d", & N, & M) {sum = 0; Low = 0; for (I = 0; I <n; I ++) {scanf ("% d", & A [I]); sum + = A [I]; If (low <A [I]) Low = A [I];} int L = low; // The minimum boundary is the maximum int r = sum; int mid; while (L <= r) {mid = (L + r)/2; if (Judge (MID) r = mid-1; elsel = Mid + 1;} printf ("% d \ n", L);} return 0 ;}