提交时间:2024-01-09 21:30:40
运行 ID: 36179
#include<bits/stdc++.h> using namespace std; int n,m,a[10005]; int judge(int x){ int money=0,month=0,i,d; for(int i=0;i<=n;i++){ money+=a[i]; if(money>=x){ month++; if(a[i]<x) money=a[i]; else return 1; } } return month>=m; } int main() { int l,r,mid; int tot=0; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; tot+=a[i]; } l=1; r=tot; while(l+1<r){ mid=(l+r)/2; if(judge(mid)){ l=mid; } else r=mid; } if(judge(l)) cout<<l<<endl; else cout<<r<<endl; return 0; }