标签:int color include als ble turn lse clu 最大值
https://www.luogu.com.cn/problem/P1873
#include<bits/stdc++.h>
using namespace std;
int n, m, a[1000005], max_h=-1;
bool check(int h){
long long sum=0;
for(int i=n-1; i>=0; i--){
if(h-a[i]<0)
sum+=a[i]-h;
else //树木高度有序,比h低的树,没有必要继续累加
break;
}
if(sum>=m)
return true;
else
return false;
}
int main()
{
cin>>n>>m;
for(int i=0; i<n; i++){
cin>>a[i];
max_h=max(max_h, a[i]);
}
sort(a, a+n);
int l=1, r=max_h;//求出ans的最大值
int ans=-1;
while(l<=r){
int mid=r-(r-l)/2;
if(check(mid)){
ans=mid;
l=mid+1;
}
else
r=mid-1;
}
cout<<ans;
return 0;
}
标签:int color include als ble turn lse clu 最大值
原文地址:https://www.cnblogs.com/tflsnoi/p/13189934.html