感觉没问题但是过不了样例
查看原帖
感觉没问题但是过不了样例
1013979
封禁用户楼主2024/10/14 18:28
#include<bits/stdc++.h> 
using namespace std;
const int N=1e6+10; 
long long a[N],n,m,k,b,c,ans,maxx;
bool cheek(int x) 
{
	long long cnt=0;
	for(int i=1;i<=n;i++)
	{
		cnt+=a[i]-x;
	}
    if(cnt>=m) return true;
    return false;
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	long long l=1,r=2e9,ans=0;
	while(l<=r)
	{
		long long mid=(l+r)/2;
		if(cheek(mid))
		{
			ans=mid;
			l=mid+1;
		}
	    else r=mid-1;
	}
	cout<<ans;
	return 0;
}
2024/10/14 18:28
加载中...