Pagini recente » Cod sursa (job #471766) | Cod sursa (job #1127548) | Cod sursa (job #1825888) | Cod sursa (job #2132218) | Cod sursa (job #2272172)
#include <iostream>
#include <fstream>
using namespace std;
int n, k, v[16001];
bool sepoate(int c)
{
int nrtr=0, capacitate=0, k;
for(int i=1; i<=n; i++)
{
if(v[i]>c)
{
return false;
}
if (v[i] > capacitate)
{
nrtr++;
capacitate = c;
}
if(nrtr > k)
return false;
capacitate -= v[i];
}
return true;
}
int cantitate(int x)
{
int r=0;
pos=1<<27;
while(pos!=0)
{
if(!sepoate(r+pas))
{
r+=pas;
}
pas/=2;
}
return r + 1;
}
int main()
{
ifstream fin("transport.in");
ofstream fout("transport.out");
fin>>n;
for(int i=1; i<=n; i++)
cin>>v[i];
fout<<capacitate(v[i]+1);
return 0;
}