Pagini recente » Cod sursa (job #2885399) | Cod sursa (job #39558) | Cod sursa (job #3198794) | Cod sursa (job #2032676) | Cod sursa (job #2437377)
#include <iostream>
#include <fstream>
using namespace std;
const int VMAX=16000 * 16000;
int v[VMAX], n, k;
ifstream in ("transport.in");
ofstream out ("transport.out");
bool suficient ( int c)
{
int nrt = 0, cc = 0;
for (int i=0; i < n; i++)
{
if(v[i]>c)
{
return false;
}
if(v[i]>cc)
{
nrt++;
cc = c;
}
cc-=v[i];
}
return (nrt <= k);
}
int main()
{
in>>n>>k;
for(int i=0; i<n; i++)
{
in>>v[i];
}
int st=1;
int dr = VMAX;
while (st < dr)
{
int m = (st + dr) / 2;
if (suficient (m))
{
dr = m;
}
else
{
st = m + 1;
}
}
out<<st;
return 0;
}