Pagini recente » Istoria paginii utilizator/mihaeladidu | Cod sursa (job #157047) | Cod sursa (job #606946) | Cod sursa (job #830564) | Cod sursa (job #1502092)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin ("transport.in");
ofstream fout ("transport.out");
int main ()
{
int n,k,a[16005],i,counting;
int maxim = 0, ok;
fin >> n >> k;
for (i=1; i<=n; i++)
{
fin >> a[i];
maxim = max(maxim, a[i]);
}
counting=1; ok=0;
int camion=0;
i=1;
maxim++;
while (ok==0)
{
/// cout << counting;
while (counting <= k)
{
if (camion + a[i] <= maxim)
{
camion += a[i];
i++;
}
else /// nu mai incape nicio saltea in camion
{
camion = 0; /// s-a golit camionul
counting++; /// s-a efectuat transportul
i++;
}
}
if (counting == k+1)
{
ok = 1;
fout << maxim << "\n";
}
else
{
i = 1;
maxim++;
camion = 0;
}
}
fin.close();
fout.close();
return 0;
}