Pagini recente » Cod sursa (job #674897) | Cod sursa (job #3149411) | Cod sursa (job #1779383) | Cod sursa (job #3146666) | Cod sursa (job #2440099)
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=16000;
const int vmax=16000;
int v[nmax+1];
int n,k;
ifstream ci ("transport.in");
ofstream co ("transport.out");
bool destul (int c)
{
int nr=0, r=0;
for (int i=0; i < n; i++)
{
if(v[i]>c)
{
return false;
}
if(v[i]>r)
{
nr++;
r=c;
}
r-=v[i];
}
return (nr<=k);
}
int main()
{
ci >> n >> k;
for(int i=0; i<n; i++)
{
ci>>v[i];
}
int st=1,dr=vmax*nmax;
while (st<dr)
{
int m=(st+dr)/2;
if ( destul(m))
{
dr=m;
}
else
{
st=m+1;
}
}
cout << st;
return 0;
}