2

3 条评论

  • @ 2025-10-3 22:06:04

    我发了

    • @ 2025-10-3 21:35:00
      #include<bits/stdc++.h>
      using namespace std;
      #define int long long
      int n,m,a[100005],l,r,mid,ans;
      bool check(int x){
      	int pos=0,sum=0;
      	for(int i=1;i<=n;i++){
      		if(pos+a[i]<=x) pos+=a[i];
      		else pos=a[i],sum++;
      	}
      	return sum>=m;
      }
      signed main(){
      	ios::sync_with_stdio(false);
      	cin.tie(0);
      	cout.tie(0);
      	//freopen("xxx.in","r",stdin);
      	//freopen("xxx.out","w",stdout);
      	cin>>n>>m;
      	for(int i=1;i<=n;i++){
      		cin>>a[i];
      		l=max(l,a[i]);
      	}
      	int r=1e9;
      	while(l<=r){
      		mid=(l+r)/2;
      		if(check(mid)) l=mid+1;
      		else r=mid-1;
      	}
      	cout<<l;
      	return 0;
      }
      
      • @ 2025-10-3 21:33:23

        需要帮助吗?

        • 1

        信息

        ID
        116
        时间
        1000ms
        内存
        256MiB
        难度
        8
        标签
        递交数
        56
        已通过
        9
        上传者