Pagini recente » Cod sursa (job #3184143) | Cod sursa (job #230993) | Cod sursa (job #1484360) | Cod sursa (job #2738415) | Cod sursa (job #2988770)
#include <fstream>
#include <climits>
using namespace std;
ifstream in ("transport.in");
ofstream out ("transport.out");
short int v[16001],n,k;
bool verif (int x)
{
short int last=0,j=k,i;
for(i=0;i<=n;i++)
{
if(v[i]-last>x)
{
last=v[i-1];
j--;
i--;
}
if(j==0)
{
if(i<n)
return 0;
break;
}
}
return 1;
}
int main()
{
short int x,i;
int suma=0,minim=INT_MAX,dr,st,m;
in>>n>>k;
for(i=1;i<=n;i++)
{
in>>x;
v[i]=x+v[i-1];
suma+=x;
}
st=suma/k;
dr=suma;
while(st<=dr)
{
m=(dr+st)/2;
if(verif(m)!=true)
st=m+1;
else
{
minim=m;
dr=m-1;
}
}
out<<minim;
return 0;
}