#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
using namespace std;
const int MAXN = 1000 + 5;
int n, k, ai[MAXN], bi[MAXN];
double p[MAXN];
bool check(double x) {
for (int i = 1; i <= n; i++) p[i] = (db)ai[i] - (db)bi[i] * x;
sort(p + 1, p + 1 + n);
double tot = 0;
for (int i = k + 1; i <= n; i++) tot += p[i];
return tot >= 0;
}
void clean() {}
void solve() {
clean();
for (int i = 1; i <= n; i++) scanf("%d", &ai[i]);
for (int i = 1; i <= n; i++) scanf("%d", &bi[i]);
double l = 0, r = 1;
for (int i = 1; i <= 100; i++) {
double mid = (l + r) / 2.0;
if (check(mid)) l = mid; else r = mid;
}
printf("%.0f\n", l * 100);
}
int main() {
while (scanf("%d%d", &n, &k) == 2 && (n || k)) solve();
return 0;
}
poj 2976(分数规划)
------ 本文结束 ------
版权声明
FlyInTheSky's blog by FlyInTheSky is licensed under a Creative Commons BY-NC-ND 4.0 International License.
由FlyInTheSky创作并维护的FlyInTheSky's blog博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证。
本文首发于FlyInTheSky's blog 博客( http://blog.flyinthesky.win/ ),版权所有,侵权必究。