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.

26 lines
510 B

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