Pagini recente » Cod sursa (job #575096) | Cod sursa (job #731755) | Cod sursa (job #2318536) | Cod sursa (job #1340222) | Cod sursa (job #686770)
Cod sursa(job #686770)
#include <cstdio>
using namespace std;
long long dr=2000000000ll,st=1,mj,sol,n,k,logic=0,a[16005],ult,i;
bool merge(int c){
long long sum=0;long long transp=0;
int i;
for(i=1;i<=n;i++){
if(sum+ a[i]>=c){
transp++;
sum=a[i];
if(transp>k)
return false;
}
else
sum=sum+a[i];
}
return (transp<=k);
};
int ad,abc;
int main(){
freopen("transport.in","r",stdin);
freopen("transport.out","w",stdout);
scanf("%lld",&n);
scanf("%lld",&k);
for(i=1;i<=n;i++)
scanf("%lld",&a[i]);
while((st<=dr)&&(logic!=1)){
mj=(st+dr)/2;
if(merge(mj)!=0){
dr=mj-1;
/* if(ult==1){
logic=1;
sol=mj;
}*/
}
else{
st=mj+1;
ult=1;
}
}
//while(merge(sol)==0)
//sol++;
printf("%lld",mj);
}