[sum a_i - x imes sum b_i
]
等同于
[sum(a_i-x imes b_i)
]
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
int n, k, uu;
double a[1005], b[1005], c[1005], l, r;
bool chk(double x){
for(int i=1; i<=n; i++) c[i] = a[i] - x * b[i];
sort(c+1, c+1+n);
double sum=0.0;
for(int i=n; i>=k+1; i--) sum += c[i];
return sum>0;
}
int main(){
while(scanf("%d %d", &n, &k)!=EOF && (n || k)){
for(int i=1; i<=n; i++){
scanf("%d", &uu);
a[i] = uu;
}
for(int i=1; i<=n; i++){
scanf("%d", &uu);
b[i] = uu;
}
l = 0.0, r = 1.0;
while(r-l>1e-6){
double mid=(l+r)/2.0;
if(chk(mid)) l = mid;
else r = mid;
}
printf("%.0f
", 100.0*l);
}
return 0;
}