#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> #include<cctype> usingnamespace std; double a[1005], b[1005]; int n, k; boolC(double x) { double suma = 0, sumb = 0; x /= 100; int i, sum = 0; for (i = 1; i <= n; i++) { if ((suma + a[i]) / (sumb + b[i]) < x) { sum++; if (sum > k) returnfalse; continue; } suma += a[i]; sumb += b[i]; } returntrue; } intmain() { int i; double l, r, m, res; while (scanf("%d%d", &n, &k)) { if ((n | k) == 0) return0; for (i = 1; i <= n; i++) scanf("%lf", &a[i]); for (i = 1; i <= n; i++) scanf("%lf", &b[i]); l = 0; r = 100; for (i = 1; i <= 100; i++) { m = l + (r - l) / 2; if (C(m)) { res = m; l = m; } else r = m; } printf("%.0f\n", res); } }
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> #include<cctype> usingnamespace std; double a[1005], b[1005], c[1005]; int n, k; boolC(double x) { int i; double sum = 0; for (i = 1; i <= n; i++) { c[i] = a[i] - b[i] * x; sum += c[i]; } sort(c + 1, c + 1 + n); for (i = 1; i <= k; i++) { sum -= c[i]; if (sum >= 0) returntrue; } returnfalse; } intmain() { int i; double l, r, m, res; while (scanf("%d%d", &n, &k)) { if ((n | k) == 0) return0; for (i = 1; i <= n; i++) scanf("%lf", &a[i]); for (i = 1; i <= n; i++) scanf("%lf", &b[i]); l = 0; r = 1; for (i = 0; i <= 100; i++) { m = l + (r - l) / 2; if (C(m)) { res = m; l = m; } else r = m; } printf("%.0f\n", res * 100); } }
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> #include<cctype> usingnamespace std; double a[1005], b[1005], c[1005]; int n, k; boolC(double x) { int i; double sum = 0; for (i = 1; i <= n; i++) { c[i] = a[i] - b[i] * x; sum += c[i]; } sort(c + 1, c + 1 + n); for (i = 1; i <= k; i++) { sum -= c[i]; if (sum >= 0) returntrue; } returnfalse; } intmain() { int i; double l, r, m; while (scanf("%d%d", &n, &k)) { if ((n | k) == 0) return0; for (i = 1; i <= n; i++) scanf("%lf", &a[i]); for (i = 1; i <= n; i++) scanf("%lf", &b[i]); l = 0; r = 1; for (i = 0; i <= 100; i++) { m = l + (r - l) / 2; if (C(m)) l = m; else r = m; } printf("%.0f\n", l * 100); } }
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> #include<cctype> usingnamespace std; double a[1005], b[1005], c[1005]; int n, k; boolC(double x) { int i; double sum = 0; for (i = 1; i <= n; i++) { c[i] = a[i] - b[i] * x; sum += c[i]; } sort(c + 1, c + 1 + n); for (i = 1; i <= k; i++) { sum -= c[i]; if (sum >= 0) returntrue; } return sum >= 0; } intmain() { int i; double l, r, m; while (scanf("%d%d", &n, &k)) { if ((n | k) == 0) return0; for (i = 1; i <= n; i++) scanf("%lf", &a[i]); for (i = 1; i <= n; i++) scanf("%lf", &b[i]); l = 0; r = 1; for (i = 0; i <= 100; i++) { m = l + (r - l) / 2; if (C(m)) l = m; else r = m; } printf("%.0f\n", l * 100); } }