题意:
我没看懂题意...
有n个数字,要把他们分成m组,每组都是连续的几个数字,要求使数字和最大的组 最小
解题思路:
二分最小数字和 判断是否能够分成至少M组
下界是max(a[1] ~a[n]) 上界是a[1] + a[2] + ....+ a[n];
code:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define eps 1e-4
#define maxd 10e4
#define mem(a, b) memset(a, b, sizeof(a))
typedef pair<int,int> pii;
typedef long long LL;
//------------------------------
const int maxn = 100005;
int a[maxn], sum;
int n,m;
int l, r;
void init(){
for(int i = 0; i < n; i++){
scanf("%d",&a[i]);
r += a[i];
l = max(l, a[i]);
}
}
bool is_ok(int x){
int cnt = 1;
int all = 0;
for(int i = 0; i < n; i++){
all = a[i] + all;
if(all > x){
cnt++;
all = a[i];
}
if(cnt > m) return false;
}
if(cnt <= x) return true;
}
void solve(){
while(l < r){
int mid = l + (r-l)/2;
if(is_ok(mid)) r = mid;
else l = mid + 1;
}
printf("%d\n",l);
}
int main(){
scanf("%d%d",&n,&m);
init();
solve();
return 0;
}