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. 203. 阿里jetcache

    [视频&交流平台] àSpringBoot视频:http://t.cn/R3QepWG à SpringCloud视频:http://t.cn/R3QeRZc à Spring Boot源码: ...

  2. Android开发 assets目录

    Android资源文件分类: Android资源文件大致可以分为两种: 第一种是res目录下存放的可编译的资源文件: 这种资源文件系统会在R.Java里面自动生成该资源文件的ID,所以访问这种资源文件 ...

  3. [Unity优化]UI优化(三):GraphicRebuild

    参考链接: https://blog.csdn.net/jingangxin666/article/details/80143176 调试过程: 1.修改Image的颜色 2.Graphic.SetV ...

  4. ORACLE_11G归档空间满,由于数据库装完后使用的是默认空间是闪回区

    1.首先根据alert跟踪日志发现归档空间满,路径大致如下:cd $ORACLE_BASE/diag/rdbms/jsswgsjk/jsswgsjk1/tracetail -f alert_jsswg ...

  5. 学习笔记:AngularJs

    站点: http://www.angularjs.cn/  angularjs中文社区 http://www.jb51.net/article/60733.htm  AngularJS内置指令 基本页 ...

  6. leetcode234

    /** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNo ...

  7. 析构方法(__del__)

    析构方法,当对象在内存中被释放时(也就是实例执行完了,实例的内存就会自动释放,这时候就会触发),自动触发执行. 当程序结束时,python只会回收自己的内存空间,即用户态内存,而操作系统的资源则没有被 ...

  8. 《DOM Scripting》学习笔记-——第二章 js语法

    <Dom Scripting>学习笔记 第二章 Javascript语法 本章内容: 1.语句. 2.变量和数组. 3.运算符. 4.条件语句和循环语句. 5.函数和对象. 语句(stat ...

  9. Web Worker模拟抢票

    web worker工作原理图: 抢票系统思维导图: 思路:五个人(5个div窗口模拟)同时进行抢票,有百分之十的几率可以抢到票,抢到票后对应的窗口(即随机生成的数大于等于0小于9的情况)会编程天蓝色 ...

  10. Windows 10 系统,配置jdk系统环境变量

    1. 下载jdk包,下载路径为:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html, ...