2 条题解
-
3
#include<bits/stdc++.h> #define int long long using namespace std; int a[300001]; int n,m; bool check(int d){ int s=0,o=0; for(int i=1;i<=n;i++){ s+=a[i]+1; if(s+a[i+1]>d){ s=0; o++; } } if(o>m){ return false; }else{ return true; } } signed main(){ cin>>n>>m; int l=-1,r=0; for(int i=1;i<=n;i++){ cin>>a[i]; r+=a[i]; l=max(l,a[i]); } a[n+1]=1e18; int p=0; while(l<=r){ int t=(l+r)/2; if(check(t)==false){ l=t+1; }else{ r=t-1; p=t; } } cout<<p; return 0; }
信息
- ID
- 4959
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 2
- 标签
- 递交数
- 16
- 已通过
- 8
- 上传者