警示后人

P2440 木材加工

xy_mc @ 2024-11-17 07:45:56

#include<bits/stdc++.h>
using namespace std;
int n,k,a[100005],ans,maxx;
bool check(int l){
    int sum=0;
    for(int i=1;i<=n;i++){
        sum+=a[i]/l;
    }
    return sum>=k;
}
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        maxx=max(maxx,a[i]);
    }
    int l=1,r=maxx;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)){
            ans=mid;
            l=mid+1;
        }else{
            r=mid-1;
        }
    }
    cout<<ans;
    return 0;
}

by xy_mc @ 2024-11-17 07:46:59

max千万补药写成min,不然会错两个点


by liuhuanjun @ 2024-11-17 10:53:57

@xy_mc你还进食上后人了,fw


|