我只写了特判都30分?
by hzb1121 @ 2022-07-21 17:14:51
# [本人博客地址](https://www.ricemoon.cn/)
```cpp
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define endl "\n"
const int N = 1e5 + 10;
const int M = 110;
void solve()
{
LL n, l, r;
cin >> n;
LL a[M], all = 0;
for (int i = 0; i < n; i ++ ) cin >> a[i], all += a[i];
cin >> l >> r;
if (all < l * n or all > r * n)
{
cout << -1 << endl;
return;
}
LL res = 0, low_num = 0, up_num = 0;
for (int i = 0; i < n; i ++ )
{
if (a[i] > r) up_num += a[i] - r;
if (a[i] < l) low_num += l - a[i];
}
cout << max(up_num, low_num);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
```
by Roger_Spencer @ 2023-02-20 09:34:32