Pagini recente » Cod sursa (job #351104) | Cod sursa (job #993525) | Cod sursa (job #1618135) | Cod sursa (job #424134) | Cod sursa (job #1259161)
#include<fstream>
#include<string>
#include<list>
#include<algorithm>
#include<iostream>
using namespace std;
int ud[500],ui[500];
int main()
{
ifstream si;
si.open("transport.in");
ofstream so;
so.open("transport.out");
int n,t;
si>>n>>t;
int c[n],tot=0,maxx=0,i;
for(i=0;i<n;++i)
{
si>>c[i];
tot+=c[i];
if(c[i]>maxx)
maxx=c[i];
}
int st,dr;
st=max(maxx,(tot+t-1)/t);
dr=tot;
int mij=st+dr;
mij=mij/2;
int tf,s,sol;
while(st<=dr)
{
// cout<<st<<' '<<mij<<' '<<dr<<endl;
tf=1;
s=0;
for(i=0;i<n;++i)
{
if(s+c[i]>mij)
{
++tf;
s=c[i];
}
else
s+=c[i];
}
//cout<<tf<<endl;
if(tf>t)
{
st=mij+1;
}
else
{
sol=mij;
dr=mij-1;
}
mij=st+dr;
mij=mij/2;
}
so<<sol;
}