0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 17:16:26 +00:00
OI-codes/Luogu/P1182/P1182.cpp

37 lines
656 B
C++
Raw Normal View History

#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], l, r, mid, ans;
bool check(int x) {
int tot = 0, num = 0;
for (int i = 1; i <= n; i++) {
if (tot + a[i] <= x) {
tot += a[i];
2021-11-19 09:01:13 +00:00
} else {
tot = a[i];
num++;
}
}
return num >= m;
}
2022-05-20 01:23:27 +00:00
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
l = max(l, a[i]);
r += a[i];
}
while (l <= r) {
mid = l + r >> 1;
if (check(mid)) {
l = mid + 1;
2021-11-19 09:01:13 +00:00
} else {
r = mid - 1;
}
}
cout << l << endl;
return 0;
}