From 1793e83e537401b40e0e142336dacbaed59aef5d Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 1 Nov 2020 16:06:11 +0800 Subject: [PATCH] =?UTF-8?q?P1109=20=E5=AD=A6=E7=94=9F=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R41010395 --- problem/P1109/P1109.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 problem/P1109/P1109.cpp diff --git a/problem/P1109/P1109.cpp b/problem/P1109/P1109.cpp new file mode 100644 index 00000000..8b564f2f --- /dev/null +++ b/problem/P1109/P1109.cpp @@ -0,0 +1,29 @@ +#include + +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; +}