Pagini recente » Cod sursa (job #620656) | Cod sursa (job #1214970) | Cod sursa (job #1497478) | ONIS 2014, Runda 1 | Cod sursa (job #1506906)
#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;
return C+1;
}
int main()
{
citire();
g << cautBin(K * 16000);
}