好烦,跟题解感觉一样啊不知道哪里错了
查看原帖
好烦,跟题解感觉一样啊不知道哪里错了
1284636
fxsnbfx楼主2024/8/13 20:41
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll n,m,a[N],ans;
ll find(ll l,ll r)
{
	while(l<=r)
	{
		ll num=0,mid=(l+r)/2;
		for(ll i=1;i<=n;i++)
		if(a[i]>mid)
		num+=a[i]-mid;
		if(num>m)
		l=mid+1;
		else
		r=mid-1;
	}
	return l;
}
void solve()
{
	cin>>n>>m;
	for(ll i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+1+n);
	ans=find(a[1],a[n]);
	cout<<ans;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL) ,cout.tie(NULL);
	int T=1;
	while(T--)
	{
		solve();
	}
	return 0;
}
2024/8/13 20:41
加载中...