1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <iostream> #include <cstdio> #include <cmath> #include <algorithm>
const double eps = 1e-12;
int n, k; double a[1123], b[1123]; double c[1123];
bool Check(double x) { for(int i = 1; i <= n; i ++) c[i] = a[i] - b[i] * x;
std:: sort(c + 1, c + n + 1);
double res = 0; for(int i = n; i > k; i --) res += c[i];
return res > 0; }
double Binary_Search() { double l = 0.0, r = 1000000000.0;
while(l + eps < r) { double mid = (l + r) / 2.0;
if(Check(mid)) l = mid; else r = mid; }
return l; }
int main() { while(~ scanf("%d%d", &n, &k)) { if(n == 0) break;
for(int i = 1; i <= n; i ++) scanf("%lf", &a[i]); for(int i = 1; i <= n; i ++) scanf("%lf", &b[i]);
printf("%d\n", int(Binary_Search() * 100.0 + 0.5)); }
return 0; }
|