讨论 / 这题不会做
wufan1214 2014-03-09 14:53:55
点我顶贴 收藏 删除
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<iostream>

using namespace std;

int a[100010];

int mid;

int n,m;

int maxx(int x,int y)

{

return x>y?x:y;

}

int check()

{

int sum=0,j=1;

for (int i=1;i<=n;i++)

{

sum+=a[i];

if (sum>mid)

{

sum=a[i];

j++;

}

}

if (j<=m) return 0;

return 1;

}

int main()

{

int left=0,right=0;

scanf("%d%d",&n,&m);

for (int i=1;i<=n;i++)

{

scanf("%d",&a[i]);

left=maxx(left,a[i]);

right+=a[i];

}

while (left!=right)

{

mid=(left+right)>>1;

if (check()) left=mid+1;

else right=mid;

}

printf("%d",right);

return 0;

}

查看更多回复
提交回复