mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 19:08:47 +00:00
#10014. 「一本通 1.2 练习 1」数列分段 II
Luogu: dc5467c0ab9cf8f2b2d0494bfae60f09313c902a LibreOJ: https://loj.ac/s/1025686
This commit is contained in:
parent
78704aba1a
commit
b9e1270a22
37
LibreOJ/10014/10014.cpp
Normal file
37
LibreOJ/10014/10014.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#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];
|
||||
} else {
|
||||
tot = a[i];
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num >= m;
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
cout << l << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user