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
|
#include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #define rep(i,x,y) for(register int i=x;i<=y;++i) #define repd(i,x,y) for(register int i=x;i>=y;--i) #define ll long long using namespace std; const int N=1e3+7; const ll lnf=0x3f3f3f3; const double esp=1e-3; struct node{ double a,b,c; inline double f(double x){c=a-b*x;} }a[N]; int n,m; inline int cmp(node x,node y){return x.c<y.c;} double solve(double x){ rep(i,1,n)a[i].f(x); sort(a+1,a+n+1,cmp); double aa=0,bb=0; repd(i,n,m+1){aa+=a[i].a;bb+=a[i].b;} return aa/bb; } double find(){ double l=0,r=solve(0); while(l+esp<r){ l=r;r=solve(r); } return l; } int main(){ while(~scanf("%d%d",&n,&m)&&(n||m)){ rep(i,1,n){scanf("%lf",&a[i].a);a[i].a*=100;} rep(i,1,n)scanf("%lf",&a[i].b); double ans=find(); printf("%.0fn",ans); } return 0; }
|
近期评论