88分求助
查看原帖
88分求助
387330
williaw楼主2021/2/4 14:28
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int n,k;
int a[500000];
bool judge(int x){
    int temp=0;
    for(int i=1;i<=n;i++){
        temp+=a[i]/x;
    }
    return temp>=k;
}
int main(){
    cin>>n>>k;
    int l=0,r=1000000000,mid;
    long long tot;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        tot+=a[i];
    }
    if(k>tot){
        cout<<"0";
    }
    else if(k<=tot){
        while(l<=r){
            mid=(l+r)/2;
            if(mid==0) break;
            if(judge(mid)) l=mid+1;//r=mid-1;
            else r=mid-1;//l=mid+1;
        }
        cout<<r;
    }
    return 0;
}


2021/2/4 14:28
加载中...