You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
432 B

#include <bits/stdc++.h>
using namespace std;
const int N = 1111;
int n, l, r;
int a[N];
int sum;
int res;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
cin >> l >> r;
if (sum < l * n || sum > r * n) {
printf("-1");
return 0;
}
for (int i = 1; i <= n; i++)
if (a[i] > r) res += a[i] - r;
printf("%d\n", res);
return 0;
}