Pagini recente » Cod sursa (job #2635901) | Cod sursa (job #1261149) | Cod sursa (job #1160293) | Cod sursa (job #2960600) | Cod sursa (job #1525806)
#include <iostream>
#include <fstream>
using namespace std;
int k,n;
int v[16001];
bool check(int cap){
int size = 0, steps = 0, i = 1;
while(steps <= k && i <= n){
steps++;
while(size + v[i] <= cap && i<=n){
size+=v[i];
i++;
}
size = 0;
}
if(steps <= k && i>=n)
return true;
return false;
}
int binary(){
int step = 1;
while(step < 2097152)
step<<=1;
int i, lastGood =0;
for(i = 0; step != 0; step>>=1)
if(check(i+step))
lastGood = i+step;
else
i+=step;
return lastGood;
}
int main()
{
ifstream fin("transport.in");
ofstream fout("transport.out");
fin>>n>>k;
for(int i=1; i<=n; i++)
fin>>v[i];
fout<<binary();
return 0;
}