Bestcoder #5 1002

Source: Internet
Author: User
Bestcoder #5 1002

Poor MitsuiTime Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 336 accepted submission (s): 70


Problem description

Because of the mess Mitsui have made, (not too long ago, Mitsui, leading a group of bully guys, intended to make some trouble and damage to the basketball team .) he was punished to mop the floor this week. and he needs to get some water first.

He takes n broken buckets to get some water. when he turns on the water-tap, the water begins to fill in at a speed V unit water per second. (and this speed will always be v .) as the buckets is broken, when there is water in the bucket, water begins to flow away at a certain speed. each bucket has its own speed. at a time, there can only be one bucket to receive water from the water-tap, but at the same time water still flows away from the buckets (those contains water at that moment ).

We don't allow a bucket to receive water from the water-tap for more than once or receive water from other buckets. and we assume that Mitsui can change the position of the buckets in a very short time (we can ignore the time it takes) and the capacity of each backet is so large that it can't be fulfilled.

Now Mitsui wonders can there be a moment that each bucket is filled with a specific volunm of water. if it's possible, find the earliest one, otherwise he will just go home in a bad mood.

 

 

Input

This problem contains multiple tests.
The first line contains a number t (1 ≤ T ≤ 150), which tells the total number of test cases.
Each test consists of three lines, the first line contains two integers, N and V. (1 ≤ n ≤ 40, 1 ≤ v ≤ 40 ). N tells the number of buckets and V tells the speed of water come out of the water-tap. in the second line, there are n integers, AI (1 ≤ AI ≤ 40) is the speed of water flow away from the I-th bucket. in the third line, there are n interges, Bi (0 ≤ Bi ≤ 40) is the volunm of water that Mitsui wants the I-th bucket to contain at that special moment.

 

 

Output

This problem is intended to use special judge. but so far, bestcoder doesn't support special judge. so if it's possible for Mitsui to optimize his movement to make that happen, you shocould output a number which tells the earliest time that might happen since Mitsui turns on the water-tap, rounded it into an integer, otherwise just output-1 instead.

 

 

Sample Input

23 31 1 32 2 23 31 1 12 2 2

 

 

Sample output

-15

Hint

In the first example, Mitsui can't make that happen no matter how he arranges the order of the buckets to receive water from the water-tap. so the answer is-1.In the second example, Mitsui can make that happen in 4.75 seconds. and that is the optimal answer. so you shoshould output 5. please note, if the accurate answer is X, you are recommended to use printf ("%. 0f \ n ", x) to output the answer in C ++.

1 # include <iostream> 2 3 # include <cstdio> 4 5 # include <cstring> 6 7 # include <vector> 8 9 # include <cmath> 10 11 # include <Map> 12 13 # include <algorithm> 14 15 # define M (, b) memset (a, B, sizeof (a) 16 17 using namespace STD; 18 19 20 21 int t; 22 23 int N; 24 25 Double V; 26 27 double time [106]; 28 29 30 31 struct bow 32 33 {34 35 double A, B; 36 37 bool operator <(const bow & RHs) const 38 39 {40 41 Return B/A> RHS. b/RHS. a; 42 43} 44 45} Bo [106]; 46 47 48 49 int main () 50 51 {52 53 scanf ("% d", & T ); 54 55 while (t --) 56 57 {58 59 scanf ("% d % lf", & N, & V); 60 61 for (INT I = 0; I <n; I ++) 62 63 {64 65 scanf ("% lf", & Bo [I]. a); 66 67} 68 69 for (INT I = 0; I <n; I ++) 70 71 {72 73 scanf ("% lf ", & Bo [I]. b); 74 75} 76 77 sort (Bo, Bo + n); 78 79 double res = 0; 80 81 int flag = 1; 82 83 for (INT I = N-1; i> = 0; I --) 84 85 {86 87 If (BO [I]. B = 0) continue; // I don't know why I need to add this sentence. I have no reason to ask hack 88 89 Bo [I]. B + = bo [I]. A * res; 90 91 If (BO [I]. a> = V & Bo [I]. b! = 0) | Bo [I]. b/(V-bo [I]. a) <0) {flag = 0; break;} 92 93 res + = bo [I]. b/(V-bo [I]. a); 94 95 // cout <res <Endl; 96 97} 98 99 If (! Flag) {puts ("-1"); continue;} 100 101 printf ("%. 0lf \ n", Res); 102 103 104} 105 return 0; 106 107}

 

Bestcoder #5 1002

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.