0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P1109 学生分组

R41010395
This commit is contained in:
Baoshuo Ren 2020-11-01 16:06:11 +08:00 committed by Baoshuo Ren
parent 19922acd32
commit 1793e83e53
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

29
problem/P1109/P1109.cpp Normal file
View File

@ -0,0 +1,29 @@
#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;
}
else if (a[i] < l) {
q += l - a[i];
}
}
if (n * r < sum) {
cout << -1 << endl;
}
else {
cout << max(p, q) << endl;
}
return 0;
}