Pagini recente » Cod sursa (job #189923) | Cod sursa (job #2628383) | Cod sursa (job #208208) | Cod sursa (job #1329801) | Cod sursa (job #1506909)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("transport.in");
ofstream g("transport.out");
#define MaxN 17000
int N, K;
int A[MaxN];
void citire()
{
f >> N >> K;
for(int i=1;i<=N;i++)
f >> A[i];
}
inline int transCount(int C)
{
int trans = 1;
for(int i=1, count = 0;i<=N;i++)
{
if(count + A[i] > C)
count = 0, ++ trans;
count += A[i];
}
return trans;
}
inline int cautBin(int maxVal)
{
int C, step;
for(step = 1;step < maxVal;step <<= 1);
for(C=1;step;step >>= 1)
if(C+step <= maxVal && transCount(C+step) > K)
C += step;
if(transCount(C) > K)
++ C;
return C;
}
int main()
{
citire();
g << cautBin(16000 * 16000);
}