最大化平均值
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int N=100000+10,D=(int)1e9+10;
const double eps=1e-6;
int n,k;
double a[N],b[N],d[N];
bool cmp(int x,int y) {return x>y;}
int main()
{
scanf("%d%d",&n,&k);
for (int i=1;i<=n;i++) scanf("%lf",&b[i]);
for (int i=1;i<=n;i++){
scanf("%lf",&a[i]);
a[i] = a[i]*b[i];}
double l,r,mid=0.0000000,h;
for (int i=1;i<=n;i++)
if (a[i]/b[i]>mid) mid=a[i]/b[i];
l=0.0000000,r=mid;
while (r-l>eps){
mid=(l+r)/2, h=0;
for (int i=1;i<=n;i++)
d[i]=a[i]-b[i]*mid;
sort(d+1,d+1+n,cmp);
for (int i=1;i<=n-k;i++)
h+=d[i];
if (h>=0.0000000) l=mid;
else r=mid-eps;
}
printf("%.6f\n",r);
return 0;
}