Cod sursa(job #732541)

Utilizator MutescuMutescu Alexandru Mutescu Data 10 aprilie 2012 17:24:02
Problema Transport Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include<cstdio>
using namespace std;
int a,b,c,d,v[16009],k,m,n,l,i=1,p=0,j=0,x=1,me=0,s=0,y=16000;
int main(){
	freopen("transport.in","r",stdin);
	freopen("transport.out","w",stdout);
	scanf("%d %d",&n,&k);
	for(l=1;l<=n;l++)
		scanf("%d",&v[l]);
	
	while(x<=y){
		me=(x+y)/2;
		while(v[i]!=0){
		while(s<me && v[i]!=0){
			s=v[i]+s;
			i++;
		}
		if(s>me){i--;
			s-=v[i];
			}
		j++;s=0;
		}
		if(j<=k)
			p=me;
		if(j>k)
			x=me+1;
		else
			y=me-1;
		j=0;i=1;
	}
	printf("%d",p);
	return 0;
}