Pagini recente » Cod sursa (job #2742550) | Cod sursa (job #754344) | Cod sursa (job #1785812) | Cod sursa (job #1449232) | Cod sursa (job #1506912)
#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=0;step;step >>= 1)
if(transCount(C+step) > K)
C += step;
return C;
}
int main()
{
citire();
g << cautBin(17000 * 16000);
}