In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be

.

Given your test scores and a positive integer k, determine how high you can make your cumulative average if you are allowed to drop any k of your test scores.

Suppose you take 3 tests with scores of 5/5, 0/1, and 2/6. Without dropping any tests, your cumulative average is . However, if you drop the third test, your cumulative average becomes .

Input

The input test file will contain multiple test cases, each containing exactly three lines. The first line contains two integers, 1 ≤ n ≤ 1000 and 0 ≤ k < n. The second line contains n integers indicating ai for all i. The third line contains npositive integers indicating bi for all i. It is guaranteed that 0 ≤ ai ≤ bi ≤ 1, 000, 000, 000. The end-of-file is marked by a test case with n = k = 0 and should not be processed.

Output

For each test case, write a single line with the highest cumulative average possible after dropping k of the given test scores. The average should be rounded to the nearest integer.

Sample Input

3 1
5 0 2
5 1 6
4 2
1 2 7 9
5 6 7 9
0 0

Sample Output

83
100

Hint

To avoid ambiguities due to rounding errors, the judge tests have been constructed so that all answers are at least 0.001 away from a decision boundary (i.e., you can assume that the average is never 83.4997).

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
#define eps 1e-7
int n,k;
double a[],b[],t[]; double gh(double x)
{
for(int i=;i<n;i++)
t[i]=a[i]-x*b[i];
sort(t,t+n);
double ans=;
for(int i=k;i<n;i++)
ans+=t[i];
return ans;
} int main()
{
while(scanf("%d %d",&n,&k))
{
if(n==&&k==) break;
for(int i=;i<n;i++)
scanf("%lf",&a[i]);
for(int i=;i<n;i++)
scanf("%lf",&b[i]);
double l=0.0,r=1.0,mid;
while(r-l>eps)
{
mid=(l+r)/;
if(gh(mid)>) l=mid;
else r=mid;
}
printf("%1.f\n",l*);
}
return ;
}

B - Dropping tests的更多相关文章

  1. POJ2976 Dropping tests(二分+精度问题)

    ---恢复内容开始--- POJ2976 Dropping tests 这个题就是大白P144页的一个变形,二分枚举x,对a[i]-x*b[i]从大到小进行排序,选取前n-k个判断和是否大于等于0,若 ...

  2. Dropping tests(01分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8176   Accepted: 2862 De ...

  3. POJ 2976 Dropping tests 01分数规划 模板

    Dropping tests   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6373   Accepted: 2198 ...

  4. POJ 2976 Dropping tests(01分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:17069   Accepted: 5925 De ...

  5. [poj P2976] Dropping tests

    [poj P2976] Dropping tests Time Limit: 1000MS  Memory Limit: 65536K Description In a certain course, ...

  6. POJ 2976 Dropping tests (0/1分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4654   Accepted: 1587 De ...

  7. HDU2976 Dropping tests 2017-05-11 18:10 39人阅读 评论(0) 收藏

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12187   Accepted: 4257 D ...

  8. POJ - 2976 Dropping tests && 0/1 分数规划

    POJ - 2976 Dropping tests 你有 \(n\) 次考试成绩, 定义考试平均成绩为 \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} ...

  9. 二分算法的应用——最大化平均值 POJ 2976 Dropping tests

    最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...

  10. 【POJ2976】Dropping Tests(分数规划)

    [POJ2976]Dropping Tests(分数规划) 题面 Vjudge 翻译在\(Vjudge\)上有(而且很皮) 题解 简单的\(01\)分数规划 需要我们做的是最大化\(\frac{\su ...

随机推荐

  1. Mac 日常使用tips

    20180725: windows标准的键盘连接了mac如何映射键盘?最大的好处是可以向后删除,还可以一键PageUP, PageDown ref: https://support.apple.com ...

  2. ES6原生Class

    es5 之前定义构造函数的方法 // 先定义一个函数,强行叫它构造函数,大写的P也不是必须的,只是约定俗成 function Point(x, y) { this.x = x; // 构造函数的属性都 ...

  3. json&pickle&shelve模块

    之前我们学习过用eval内置方法可以将一个字符串转成python对象,不过,eval方法是有局限性的,对于普通的数据类型,json.loads和eval都能用,但遇到特殊类型的时候,eval就不管用了 ...

  4. 使用jQuery+huandlebars中with应用及with+this应用

    兼容ie8(很实用,复制过来,仅供技术参考,更详细内容请看源地址:http://www.cnblogs.com/iyangyuan/archive/2013/12/12/3471227.html) w ...

  5. AD+DMA+USART实验中的收获和总结

    由于实验室用的是USART3接口,但是在基地实验时,由于没有RS232,只能换到USART1,进行实验.(在交作业的时候,记得要再换回去) 在这个过程中,遇到困难,用串口软件发送数据时无响应,应该意味 ...

  6. Swagger注解

    swagger注解说明  1.与模型相关的注解,用在bean上面 @ApiModel:用在bean上,对模型类做注释: @ApiModelProperty:用在属性上,对属性做注释 2.与接口相关的注 ...

  7. nginx-web身份验证

    1.配置文件设置: server { listen 80; server_name www.longshuai.com www1.longshuai.com; location / { root /w ...

  8. HDU-1078.FatMouseandCheese(线性dp + dfs)

    本题大意:在一个n * n的迷宫内进行移动,左上角为初始位置,每次可以走的步数不能超过m,并且每次走的方格上面的数字要大于前一次走的放个数字,不能走到格子外面,问如何能使得到的数字和最大. 本题思路: ...

  9. 10.13 新版本go on~

    上午1.5 终审 and 排期 合同管理那边又是切换选项时各种联动,我第一想法是 好麻烦,不想做这个...第二想法才是给我做吧 锻炼锻炼我 然后 分任务的时候 分给我了,,哈哈 开心 虽然我没想躲 但 ...

  10. ionic3搭建笔记及编译成apk

    一.安装node.js 二.安装Ionic2 npm install -g ionic (安装最新版本) ionic -v //查看版本号(是否安装成功) npm uninstall -g ionic ...