60pts求助
查看原帖
60pts求助
819319
wattzyh楼主2024/9/29 21:31
#include<iostream>
#define int long long 
using namespace std;
int n,m;
int a[100009];
bool check(int x){
	int cnt=0;
	for(int i=0;i<n;i++) cnt+=max(0ll,a[i]-x);
	if(cnt>=m) return true;
	return false;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int maxn=-1;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		maxn=max(maxn,a[i]);
	}
	int l=1,r=maxn;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)) l=mid+1;
		else r=mid-1;
	}
	cout<<r;
	return 0;
}
2024/9/29 21:31
加载中...