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
25 lines
465 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
int a[110];
|
|
int l, r;
|
|
int n;
|
|
int sum;
|
|
int s1, s2;
|
|
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");
|
|
exit(0);
|
|
}
|
|
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);
|
|
return 0;
|
|
} |