Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
128029 | 周歆童(初一23 | 花费 | C++ | 解答错误 | 40 | 0 MS | 260 KB | 418 | 2024-01-25 11:30:54 |
#include<bits/stdc++.h> using namespace std; int n,m,a[100005],l=1,r,mid; int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; r+=a[i]; } while(l<r){ mid=l+(r-l+1)/2; int sum=0,cnt=1; for(int i=1;i<=n;i++){ sum+=a[i]; if(sum>mid){ cnt++; sum=a[i]; } } if(cnt<=m)r=mid-1; else l=mid; //printf("l=%d,r=%d,mid=%d\n",l,r,mid); } cout<<mid; return 0; }