Pagini recente » Cod sursa (job #696651) | Cod sursa (job #1227936) | Cod sursa (job #1017412) | Cod sursa (job #2225096) | Cod sursa (job #1525820)
#include <iostream>
#include <fstream>
using namespace std;
int k,n;
int v[16001];
bool check(unsigned int cap){
unsigned int size = 0;
int 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(){
unsigned int step = 4294967295;
unsigned 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;
}