From 4f526ea1891109b3c4d517bb5543a37b3dc759a2 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 3 Jan 2021 14:30:50 +0800 Subject: [PATCH] =?UTF-8?q?P3743=20kotori=E7=9A=84=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R44571071 --- Luogu/problem/P3743/P3743.cpp | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Luogu/problem/P3743/P3743.cpp diff --git a/Luogu/problem/P3743/P3743.cpp b/Luogu/problem/P3743/P3743.cpp new file mode 100644 index 00000000..e471c308 --- /dev/null +++ b/Luogu/problem/P3743/P3743.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + +int n; +double p, a[100005], b[100005]; +double sum, l, r = 1e10, mid; + +bool check(double mid) { + double q = mid * p; + sum = 0; + for (int i = 0; i < n; i++) { + if (a[i] * mid > b[i]) { + sum += a[i] * mid - b[i]; + } + } + return sum <= q; +} + +int main() { + cin >> n >> p; + for (int i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + sum += a[i]; + } + if (sum <= p) { + cout << -1 << endl; + return 0; + } + while (r - l > 1e-6) { + mid = (l + r) / 2; + if (check(mid)) { + l = mid; + } else { + r = mid; + } + } + cout << fixed << setprecision(10) << l << endl; + return 0; +}