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).
二分基础题
1 #include <iostream> 2 using namespace std; 3 #include<string.h> 4 #include<set> 5 #include<stdio.h> 6 #include<math.h> 7 #include<queue> 8 #include<map> 9 #include<algorithm> 10 #include<cstdio> 11 #include<cmath> 12 #include<cstring> 13 #include <cstdio> 14 #include <cstdlib> 15 #include<stack> 16 #include<vector> 17 double a[1100]; 18 double b[1100]; 19 double c[1100]; 20 const double MIN=1e-7; 21 int n,m; 22 int main() 23 { 24 while(cin>>n>>m) 25 { 26 if(n==0&&m==0) 27 break; 28 for(int i=1;i<=n;i++) 29 cin>>a[i]; 30 for(int i=1;i<=n;i++) 31 cin>>b[i]; 32 double kaishi=0.0,jieshu=1.0; 33 double mid; 34 while(jieshu-kaishi>MIN) 35 { 36 mid=(kaishi+jieshu)/2.0; 37 //cout<<mid<<"_"<<endl; 38 for(int i=1;i<=n;i++) 39 c[i]=a[i]-mid*b[i]; 40 sort(c+1,c+1+n); 41 double sum=0; 42 for(int i=m+1;i<=n;i++) 43 sum+=c[i]; 44 if(sum>=0) 45 kaishi=mid; 46 else 47 jieshu=mid; 48 } 49 int qqq=mid*1000; 50 if(qqq%10>=5) 51 qqq+=10; 52 qqq/=10; 53 cout<<qqq<<endl; 54 } 55 return 0; 56 }