###求助,第四个点wa了
查看原帖
###求助,第四个点wa了
575304
syc1281702660楼主2021/10/31 10:28

#include<bits/stdc++.h>
using namespace std;
int a[100005],N,M,L,R,mid;
bool check(int x){
	int sum=0,cnt=0;
	for(int i=0;i<N;i++){
		if(sum+a[i]<=x) sum+=a[i];
		else sum=a[i],cnt++;
	}
	return cnt>=M;
}
int main(){
	cin>>N>>M;
	for(int i=0;i<N;i++){
		cin>>a[i];
		L=max(L,a[i]);
		R=R+a[i];
	}
	while(L+1<R){
		mid=(L+R+1)/2;
		if(check(mid))	L=mid;
		else R=mid;
	}
	cout<<L+1;
	
	return 0;
}  
2021/10/31 10:28
加载中...