Pagini recente » Cod sursa (job #839429) | Cod sursa (job #2063466) | Cod sursa (job #873420) | Cod sursa (job #2741011) | Cod sursa (job #2637795)
#include <bits/stdc++.h>
using namespace std;
int n, k, V[16005], maxim, rez;
void fast ()
{
ios_base::sync_with_stdio(false);
cin.tie();
}
bool check (int x)
{
int cx=x;
int nr=1;
int i=1;
while (i<=n)
{
if (x>=V[i])
{
x=x-V[i];
i++;
}
else
{
nr++;
x=cx;
}
}
if (nr<=k)
return 1;
else return 0;
}
int cautbin (int st, int dr)
{
while (st<dr)
{
int mij=(st+dr)/2;
if (check(mij)==1)
{
rez=mij;
dr=mij-1;
}
else
st=mij+1;
}
return rez;
}
int main()
{
fast();
freopen("transport.in","r", stdin);
freopen("transport.out","w", stdout);
cin >> n >> k;
for (int i=1; i<=n; i++)
{
cin >> V[i];
if (V[i]>maxim)
maxim=V[i];
}
cout << cautbin (maxim, 256000000);
return 0;
}