原文链接:https://www.luogu.com.cn/problem/P2440
AC代码:
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
ll n,k,lef=0,rig=0,ans=0;
vector<ll> vec;
ll judge(ll now){
ll i,j,tim=0;
for(i=0;i<vec.size();i++){
tim+=vec[i]/now;
}
return tim>=k;
}
int main(){
ll i,j;
cin>>n>>k;
for(i=0;i<n;i++){
cin>>j;
vec.push_back(j);
lef=lef>j?j:lef;
rig=rig>j?rig:j;
}
while(lef<=rig&&rig!=0){
ll mid=(lef+rig)/2;
//cout<<lef<<" "<<mid<<" "<<rig<<endl;
int flag=judge(mid);
if(flag){
ans=mid;lef=mid+1;
}
else{
rig=mid-1;
}
}
cout<<ans<<endl;
return 0;
}