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

Description

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 n positive 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).

Source

 
 

给定ai和bi,求100*sigma(ai*xi)/sigma(bi*xi)的最大值,xi=0或1,且只能有k个为0。

即可以去掉k个(ai,bi)对。

y=100*sigma(ai)/sigma(bi)

t(y)=100*sigma(ai)-y*sigma(bi)

求t(y0)=0;

当t(y)<0时,y太大,y0<y;

当t(y)>0时,y太小,y<y0;

所以可以二分y的值。

去哪k个更优了?

要使y更大就应该是t(y)>0这种情况更可能的出现,所以对100*ai-bi排序,去掉小的k个。使t(y)>0城里更有可能。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath> using namespace std; const int N=;
const double eps=1e-; int n,k;
double a[N],b[N],score[N]; int main(){ //freopen("input.txt","r",stdin); 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=,r=,mid,sum;
while(r-l>eps){
mid=(l+r)/;
for(int i=;i<n;i++)
score[i]=*a[i]-mid*b[i];
sort(score,score+n);
sum=;
for(int i=k;i<n;i++)
sum+=score[i];
if(sum>)
l=mid;
else
r=mid;
}
printf("%.0f\n",l);
}
return ;
}

最新文章

  1. core文件
  2. 纪念逝去的岁月——C++实现一个栈
  3. 是否采用Sybase形式的自动字符串转义(用 &#39;&#39; 表示 &#39;)
  4. Ant build ${renderscript.opt.level}问题解决方案
  5. [JavaScript] 初中级Javascript程序员必修学习目录
  6. 兔子--R.java丢失原因及解决的方法
  7. javascript改变背景/字体颜色(Through the javascript to change the background and font color)
  8. mercurial(Hg) Server 搭建 过程记录
  9. HeadFirst设计模式读书笔记--目录
  10. Linux系统服务 1 ---- rSyslog日志服务
  11. jenkins配置.net mvc网站
  12. 化繁为简 经典的汉诺塔递归问题 in Java
  13. 【Sqoop篇】----Sqoop从搭建到应用案例
  14. FC105 FC106 Scale功能块使用说明
  15. H5端密码控件自动化测试
  16. transform 图标旋转,IE8、IE7不兼容
  17. Netty4.x 源码实战系列(一): 深入理解ServerBootstrap 与 Bootstrap
  18. flume杀掉重启
  19. 布式实时日志系统(三) 环境搭建之centos 6.4下hadoop 2.5.2完全分布式集群搭建最全资料
  20. c# 修改pdf

热门文章

  1. BigDecimal 的幂次方运算
  2. 结构体指针之 段错误 具体解释(segmentation fault)
  3. Android 自定义 ListView 上下拉动刷新最新和加载更多
  4. jquery 文字滚动大全 scroll 支持文字或图片 单行滚动 多行滚动 带按钮控制滚动
  5. javascript string replace 正则替换
  6. JavaScript的valueOf和toString
  7. SpringMVC+SPring+Maven+Mybaits+Shiro+Mybaits基础开发项目
  8. 朴素贝叶斯分类器(Naive Bayes)
  9. ES6学习笔记八:类与继承
  10. 【转发】JQuery中操作Css样式的方法