From 5d0e00416e81c3e0ee1b69ff778e8cc0885a3d80 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 30 Dec 2020 21:40:20 +0800 Subject: [PATCH] =?UTF-8?q?P1873=20=E7=A0=8D=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R44441314 --- problem/P1873/P1873.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 problem/P1873/P1873.cpp diff --git a/problem/P1873/P1873.cpp b/problem/P1873/P1873.cpp new file mode 100644 index 00000000..372a64e2 --- /dev/null +++ b/problem/P1873/P1873.cpp @@ -0,0 +1,35 @@ +#include + +using namespace std; + + +long long n, m, l, r, ans, a[1000005]; + +bool check(long long x) { + long long t = 0; + for (long long i = 1; i <= n; i++) { + if (a[i] > x) { + t += a[i] - x; + } + } + return t >= m; +} + +int main() { + cin >> n >> m; + for (long long i = 1; i <= n; i++) { + cin >> a[i]; + r = max(r, a[i]); + } + while (l <= r) { + long long mid = l + r >> 1; + if (check(mid)) { + l = (ans = mid) + 1; + } + else { + r = mid - 1; + } + } + cout << ans << endl; + return 0; +}