Pagini recente » Cod sursa (job #1340449) | Cod sursa (job #2555010) | Cod sursa (job #2677340) | Cod sursa (job #2480279) | Cod sursa (job #3272744)
#ifdef LOCAL
#include <bits/stdc++.h>
using namespace std;
ifstream fin("file.in");
ofstream fout("file.out");
#else
#include <bits/stdc++.h>
using namespace std;
ifstream fin("transport.in");
ofstream fout("transport.out");
#endif
int n,v[100005],k,macs,inf=300000000;
int drumuri(int cox)
{
int aux=0,cnt=0,i=1;
while(i<=n)
{
cnt++;
aux=0;
while(aux+v[i]<=cox)
{
aux+=v[i];
++i;
}
}
return cnt;
}
int binsrc()
{
int l=macs,h=inf,mid;
while(l<h)
{
mid=(l+h)/2;
if(drumuri(mid)>k)
{
l=mid+1;
}
else h=mid;
}
return h;
}
int main()
{
fin>>n>>k;
for(int i=1;i<=n;++i)
{
fin>>v[i];
macs=max(macs,v[i]);
}
fout<<binsrc();
return 0;
}