F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Poor Mitsui

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1445    Accepted Submission(s): 117


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 should 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
2 3 3 1 1 3 2 2 2 3 3 1 1 1 2 2 2
 

Sample Output
-1 5
 

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 should 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++.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-25 08:08:07, Gzip enabled