Pagini recente » Cod sursa (job #1352403) | Cod sursa (job #2909605) | Cod sursa (job #2770110) | Cod sursa (job #1352773) | Cod sursa (job #2123822)
#include <fstream>
using namespace std;
ifstream f("transport.in");
ofstream g("transport.out");
int n,i,j,dr,st,ss,sol,mij,k,v[16005],s,max1,nr;
int main()
{
f>>n>>k;
for(i=1; i<=n; i++)
{
f>>v[i];
s=s+v[i];
max1=max(v[i],max1);
//g<<v[i];
}
//g<<s<<" "<<max1;
st=max1;
dr=s;
while(st<=dr)
{
mij=(st+dr)/2;
nr=1;
ss=0;
for(i=1; i<=n; i++)
{
if(ss+v[i]<=mij)ss=ss+v[i];
else
{
nr++;
ss=v[i];
}
}
if(k<nr)
{
st=mij+1;
}
else
{
dr=mij-1;
sol=mij;
}
}
g<<sol;
return 0;
}