吃零食 ZZULIOJ - 2488

题解

考虑吃完之后剩余零食数量为多少 剩余/N(整除)为剩余最低高度 这个高度不能超过最开始的最低高度 取min

AC代码

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 10;
ll a[MAXN];

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	ll N, M, s = 0, mi = INF;
	cin >> N >> M;
	for (int i = 0; i < N; i++)
		scanf("%lld", &a[i]), s += a[i], mi = min(mi, a[i]);
	if (M > s)
		cout << -1 << endl;
	else
		cout << min(mi, (s - M) / N) << endl;

	return 0;
}

猜你喜欢

转载自blog.csdn.net/CaprYang/article/details/85224302