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.

25 lines
465 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
1 year ago
int a[110];
int l, r;
int n;
2 years ago
int sum;
1 year ago
int s1, s2;
2 years ago
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");
1 year ago
exit(0);
2 years ago
}
1 year ago
for (int i = 1; i <= n; i++) {
if (a[i] > r) s1 += a[i] - r;
if (a[i] < l) s2 += l - a[i];
}
cout << max(s1, s2);
2 years ago
return 0;
}