Pagini recente » Cod sursa (job #678109) | Cod sursa (job #274641) | Cod sursa (job #1508498)
#include <fstream>
using namespace std;
ifstream fin("transport.in");
ofstream fout("transport.out");
int a[16005],n,k,i,vol,c,mid,l,r,s;
void cit()
{
fin>>n>>k;
for(i=1;i<=n;i++)
{
fin>>a[i];
}
}
int check()
{
c=0;vol=0;
for(i=1;i<=n;i++)
{
if(vol+a[i]<=mid)
{
vol+=a[i];
}
else
{
c++;
vol=a[i];
}
}
if(c+1>k){return 0;}
else{return 1;}
}
int main()
{
cit();
l=1;r=16000*16000;
mid=(l+r)/2;
while(l<r)
{
if(check()){r=mid;s=mid;}
else{l=mid+1;}
mid=(l+r)/2;
}
fout<<s<<"\n";
}