样例过了,但是测试点就过了1,其他全部wa
查看原帖
样例过了,但是测试点就过了1,其他全部wa
1250563
Celestinefly楼主2024/4/6 16:34
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e6+10;
typedef long long LL;
int m,n;

int r,l;

LL h[N];

LL get(LL x){
    LL cnt=0;
    for(int i=1;i<=n;i++){
        if(h[i]>x)cnt+=(h[i]-x);
    }
    return cnt;
}

int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    sort(h+1,h+1+n);
    r=h[n],l=h[1];
    while(l<=r){
        int mid=(l+r)/2;
        if(get(mid)>m){
            l=mid+1;
        }else if(get(mid)==m){
            r=mid-1;
        }else{
            r=mid-1;
        }
    }
    cout<<l;
    return 0;
}

2024/4/6 16:34
加载中...