题解
2023-08-14 17:01:41
发布于:广东
8阅读
0回复
0点赞
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int a[112358];//斐波那契额数列作证
int run_out,m,x=0,s;
bool check_loct_shut(int y){
int c=1;
int sumless_in=0;//以此佐证
for(int i=1;i<=n;i++){
if(y>=sumless_in+a[i]){
sumless_in+=a[i];
}else{
c++;
sumless_in=a[i];
}
}
return c<=m;
}
int main(){
cin>>run_out>>m;
for(int i=1;i<=run_out;i++){
cin>>a[i];
if(x<a[i]){
x=a[i];
}
s+=a[i];
}
int l=x,re=s;
int ans_number=s;
while(l<=re){
int m=(l+re)/2;
if(check_loct_shut(m)){
re=m-1;
ans_number=m;
}else{
l=m+1;
}
}
cout<<ans;
return 0;
}
这里空空如也
有帮助,赞一个