Cod sursa(job #1311556)
Utilizator | Data | 8 ianuarie 2015 12:57:37 | |
---|---|---|---|
Problema | Transport | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.96 kb |
#include <iostream>
#include <fstream>
#define nmax 16002
using namespace std;
int v[nmax];
int main()
{
int n,k,max=0,x,cap,i,j,min,kp;
ifstream f("transport.in");
ofstream g("transport.out");
f>>n>>k;
for(int i=1; i<=n; i++)
{
f>>x;
v[i]=x;
if(max<x)
{
max=x;
}
}
for(i=max; ; i++)
{
kp=k;
cap=i;
for(j=1; kp>0&&j<=n-1; j++)
{
if(cap-v[j]==0)
{
kp--;
cap=i;
}
else
{
if(cap-v[j]<0)
{
kp--;
cap=i-v[j];
}
else
{
cap-=v[j];
}
}
}
if(j==n&&cap-v[j]>0)
{
g<<i;
break;
}
}
return 0;
}