0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-18 07:31:58 +00:00
OI-codes/Luogu/P1109/P1109.cpp

28 lines
511 B
C++
Raw Normal View History

2020-11-01 08:06:11 +00:00
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[55], l, r;
int p = 0, q = 0, sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
cin >> l >> r;
for (int i = 0; i < n; i++) {
if (a[i] > r) {
p += a[i] - r;
2021-11-19 09:01:13 +00:00
} else if (a[i] < l) {
2020-11-01 08:06:11 +00:00
q += l - a[i];
}
}
if (n * r < sum) {
cout << -1 << endl;
2021-11-19 09:01:13 +00:00
} else {
2020-11-01 08:06:11 +00:00
cout << max(p, q) << endl;
}
return 0;
}