From bc3cfa7174fd8b13b7f40a3b093a82c4230b7512 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sat, 21 Aug 2021 14:48:17 +0800 Subject: [PATCH] =?UTF-8?q?750.=20[2018=E5=9B=BD=E5=BA=86=E9=9B=85?= =?UTF-8?q?=E7=A4=BC=E9=9B=86=E8=AE=AD10-6T1]=20Merchant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/20508 --- S2OJ/750/750.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 S2OJ/750/750.cpp diff --git a/S2OJ/750/750.cpp b/S2OJ/750/750.cpp new file mode 100644 index 00000000..f0ecf1a9 --- /dev/null +++ b/S2OJ/750/750.cpp @@ -0,0 +1,42 @@ +#include + +using namespace std; + +int n, m, k[1000005], b[1000005]; +long long c[1000005], s, ans; + +bool check(int t) { + long long sum = 0; + for (int i = 0; i < n; i++) { + c[i] = 1ll * k[i] * t + b[i]; + } + nth_element(c, c + m, c + n, greater()); + for (int i = 0; i < m; i++) { + if (c[i] >= 0) sum += c[i]; + if (sum >= s) return true; + } + return false; +} + +int main() { + cin >> n >> m >> s; + for (int i = 0; i < n; i++) { + cin >> k[i] >> b[i]; + } + if (check(0)) { + cout << 0 << endl; + exit(0); + } + int l = 0, r = 1e9 + 1; + while (l <= r) { + int mid = l + r >> 1; + if (check(mid)) { + r = mid - 1; + ans = mid; + } else { + l = mid + 1; + } + } + cout << ans << endl; + return 0; +}