Pagini recente » Borderou de evaluare (job #2990908) | Borderou de evaluare (job #1205908) | Borderou de evaluare (job #935863) | Borderou de evaluare (job #805110) | Cod sursa (job #1009194)
#include <cstdio>
using namespace std;
int v[16002],N,K;
bool verificare(int x){
int s=0,camion=0;
for(int i=1;i<=N;i++){
if(v[i]>x){
return 0;
}
if(s+v[i]>x){
camion++;
s=v[i];
}
else{
s+=v[i];
}
}
camion++;
if(camion<=K){
return 1;
}
else{
return 0;
}
}
int binary(int st,int dr){
while(st<=dr){
if(verificare((st+dr)/2)==1){
dr=(st+dr)/2-1;
}
else{
st=(st+dr)/2+1;
}
}
return st;
}
int main()
{
freopen("transport.in","r",stdin);
freopen("transport.out","w",stdout);
scanf("%d%d",&N,&K);
for(int i=1;i<=N;i++){
scanf("%d",&v[i]);
}
printf("%d",binary(1,256000000));
return 0;
}