# [本人博客地址](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:07
```c
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, a[51], sum = 0, x = 0, y = 0, l = 0, r = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
cin >> l >> r;
if (sum > n * r || sum < n * l) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) {
if (a[i] < l) x += (l - a[i]);
if (a[i] > r) y += (a[i] 1. - r);
}
cout << max(x, y);
return 0;
}
```
by xuebi8047 @ 2023-05-07 16:47:47