Pagini recente » Cod sursa (job #389471) | Cod sursa (job #512603) | Cod sursa (job #3233458) | Cod sursa (job #1564203) | Cod sursa (job #3274238)
#ifdef LOCAL
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fantastice.in");
ofstream fout("fantastice.out");
#else
#include <bits/stdc++.h>
using namespace std;
ifstream fin("transport.in");
ofstream fout("transport.out");
#endif
int n, k, v[16005];
int h, l=16001, mid;
int main()
{
fin>>n>>k;
for(int i=1; i<=n; i++){
fin>>v[i];
l=min(l, v[i]);
}
h=n*16000;
while(l<h){
mid=(l+h)/2;
int cnt=1, s=0;
for(int i=1; i<=n; i++){
s+=v[i];
if(s>mid){
cnt++;
s=v[i];
}
}
if(cnt>k){
l=mid+1;
//cout<<mid<<" 1\n";
}else{
h=mid;
//cout<<mid<<" 2\n";
}
}
fout<<h;
return 0;
}