Pagini recente » Cod sursa (job #1369638) | Cod sursa (job #1352754) | Cod sursa (job #1353416) | Cod sursa (job #2988083) | Cod sursa (job #3211673)
#include <fstream>
#define INF 260000000
using namespace std;
ifstream cin("transport.in");
ofstream cout("transport.out");
int n,k,s[16005];
bool verif(int g){
int c=0,vf=n;
while(c<=k){
int st=1,dr=vf,poz=-1;
while(st<=dr){
int mid=(st+dr)/2;
if(s[vf]-s[mid-1]<=g)
dr=mid-1,poz=mid;
else
st=mid+1;
}
if(poz==-1)
return 0;
vf=poz-1;
c++;
if(vf==0&&c<=k)
return 1;
}
return 0;
}
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>s[i];
s[i]+=s[i-1];
}
int st=0,dr=INF,sol=0;
while(st<=dr){
int mid=(st+dr)/2;
if(verif(mid))
dr=mid-1,sol=mid;
else
st=mid+1;
}
cout<<sol;
return 0;
}