#7#8WA了,求各位大佬调一下

P2440 木材加工

MHOL @ 2024-10-08 09:58:47

#include<bits/stdc++.h>
using namespace std;
const long long N=1e8+5;
int n,k,a[N],sum;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n,greater<>());
    int r=sum/k,l=1;
    while(l<=r){
        int mid=(l+r)/2;
        int ans=0;
        for(int i=0;i<n;i++){
            ans+=a[i]/mid;
        }
        if(ans<k)r=mid-1;
        else l=mid+1;

    }
    if(l<1||r<1)cout<<"0";
    else cout<<(l+r)/2;

    return 0;
}

by MHOL @ 2024-10-08 10:00:50

@MHOL 没事了没事了,谢谢大家,这波真的是不开long long见祖宗了


|