#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int v[1001];
int n,m;
int container_num(int size)
{
int sum=0;
int count=0;
for(int i=0;i<n;i++)
{
if(sum+v[i]>size)
{
sum=v[i];
count++;
}
else
sum+=v[i];
}
return count+1;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
int max=0;
int sum=0;
for(int i=0;i<n;i++)
{
scanf("%d",&v[i]);
sum+=v[i];
if(max<v[i]) max=v[i];
}
int l=max;
int h=sum;
int mid;
while(l<h)
{
mid=(l+h)/2;
if(container_num(mid)<=m)
h=mid;//仔细想想为什么不是mid-1?
else
l=mid+1;
}
;
printf("%d\n",l);
}
}
uva11413
最新推荐文章于 2020-04-18 19:16:31 发布