Pagini recente » Cod sursa (job #695743) | Cod sursa (job #722898) | Cod sursa (job #1513832) | Cod sursa (job #5898) | Cod sursa (job #1663629)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("transport.in");
ofstream fout ("transport.out");
int n, k, x=0, c, i, v[16001], l1=0, l2=0, m;
fin>>n>>k;
for (i=0; i<n; i++)
{
fin>>v[i];
l2=l2+v[i];
if (v[i]>l1)
l1=v[i];
}
while (l1<=l2)
{
i=0;
x=0;
c=(l2+l1)/2;
while (i<n)
{
m=0;
while (m+v[i]<=c && i<n)
{
m=m+v[i];
i++;
}
x++;
}
if (x<=k)
l2=c-1;
else l1=c+1;
}
fout<<c;
return 0;
}