# 牛客网暑期ACM多校训练营（第五场）A gpa【分数规划】

https://www.nowcoder.com/acm/contest/143/A

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iomanip>
using namespace std;
const int maxn = 1e5 + 12;
const double eps = 1e-8;
int n, k;
struct node {
int s, c; double d;
}a[maxn];
double del[maxn];
int cmp(node a, node b) {
return a.d < b.d;
}
int cal(double x) {
for (int i = 1; i <= n; i++) {
a[i].d = 1.0*(1.0*a[i].c - x)*a[i].s;
//cout << a[i].d << endl;
}
//cout << endl;
sort(a + 1, a + 1 + n, cmp);
double tmp = 0.0;
for (int i = k + 1; i <= n; i++) {
tmp += a[i].d;
}
if (tmp > eps) return 1;
else return 0;
}
int main()
{
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].s);

}
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].c);
}
double L = 0.0, R = 10000.0; double ans = 0;
//cout << cal(2.7) << endl;
while (R - L > eps) {
double M = (L + R) / 2;
if (cal(M)) ans = M, L = M;
else R = M;
}
printf("%.10f\n", ans);
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120