Pagini recente » Cod sursa (job #1652678) | Cod sursa (job #1740287) | Cod sursa (job #983907) | Cod sursa (job #280406) | Cod sursa (job #670157)
Cod sursa(job #670157)
#include<cstdio>
const int N = 16002;
int n, k, a[N];
void citire() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
}
bool ok(int x) {
int cx = x, nrt = 1;
for (int i = 1; i <= n; ++i) {
if (a[i] > cx)
return false;
if (a[i] > x) {
++nrt;
if (nrt > k)
return false;
x = cx - a[i];
continue;
}
x -= a[i];
}
return true;
}
int cautbin() {
int i, pas = 1 << 28;
for (i = 0; pas; pas >>= 1)
if (!ok(i + pas))
i += pas;
return i + 1;
}
int main() {
freopen("transport.in", "r", stdin);
freopen("transport.out", "w", stdout);
citire();
printf("%d\n", cautbin());
return 0;
}