70分求助,WA了#3 #9 #10
查看原帖
70分求助,WA了#3 #9 #10
229117
ZeroTwo楼主2020/8/22 17:13
#include<bits/stdc++.h>

using namespace std;

long long n,m,maxn = 0;
long long tree[1000100];

int check(long long x)
{
	long long  mm = 0;
	for (int i = 1;i <= n; i ++)
		if (tree[i] > x)
			mm += tree[i] - x;
	return mm;
}

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i ++)
	{
		cin >> tree[i];
		maxn = max(maxn, tree[i]);
	}
	long long l = 1, r = maxn;
	while(l < r)
	{
		long long mid = l + r >> 1; 
		if (check(mid) < m)	r = mid;
		else l = mid + 1;	
	}
	cout << l - 1;
	return 0;
}
2020/8/22 17:13
加载中...