建议降红

P2440 木材加工

xy_mc @ 2024-11-16 15:20:36

#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 Lwx112412 @ 2024-11-16 15:21:41

6


by cly312 @ 2024-11-16 15:25:41

@xy_mc 二分属于算法


by Iggle_Piggle @ 2024-11-16 15:28:25

@xy_mc lz这么强相比可以AK cpsj吧/qiang


by MinimumSpanningTree @ 2024-11-16 15:33:01

orz


by BigJoker @ 2024-11-16 15:39:41

为啥?


by liuhuanjun @ 2024-11-16 16:21:29

还不是老师教的(叫啥叫)


by xy_mc @ 2024-11-16 16:37:54

@liuhuanjun 那你第一次为什么才十二分?


by liuhuanjun @ 2024-11-16 16:53:44

@xy_mc!@#¥%……&*()


by xy_mc @ 2024-11-16 17:01:04

@liuhuanjun 急了<-


by liuhuanjun @ 2024-11-16 17:02:18

@xy_mc你急了,指自己干嘛,没发烧啊


| 下一页