无故超时求调
查看原帖
无故超时求调
1009027
stils楼主2023/12/15 21:04
#include<bits/stdc++.h>
using namespace std;
const int N=1000006;
int n,m;
int tree[N];

int max_h=0;

int ans;

bool check(int x){
    int res=0;
    for(int i=1;i<=n;i++){
        if(tree[i]>x)res+=tree[i]-x;//把这里改了就不会超时
    }
    if(res>=m)return true;
    else return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>tree[i];
        max_h=max(tree[i],max_h);
    }
    int l=1,r=max_h;
    while(l<=r){
        int mid=(l+r)>>2;
        if(check(mid)){
            ans=mid;
            l=mid+1;
        }
        else{
            r=mid-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}
2023/12/15 21:04
加载中...