dev能编译,提交就编译失败,用的自动识别语言
查看原帖
dev能编译,提交就编译失败,用的自动识别语言
1620862
A3227257928楼主2024/12/18 19:44
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+9;
int arr[N],n,end;
long long m,ans;

int cmp(int x,int y)
{
	return x>y;
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n >> m;
	for(int i= 1;i<=n;i++)cin >> arr[i];
	sort(arr+1,arr+1+n,cmp);
	for(int h = arr[1];h>=0;h--)
	{
		ans = 0;
		for(int i = 1;i<=n;i++)
		{
			if(arr[i]>h)ans+=arr[i]-h;
		}
		if(ans == m)
		{
			end = h;
			break;
		}
	}
	 cout << end << endl;
	return 0;
}
2024/12/18 19:44
加载中...