The one who works is the one who eats... nothing
Time limit1sMemory limit256 MB
Given the worker has finished p percent of the job and eaten q percent of the food, find the minimum number of helpers, each a times faster and b times slower eaters, to finish before food runs out, or -1.
- Level
Medium4 of 10
- Topics
- Math, Binary search, Implementation, Greedy
- Solved
- No attempts yet
Problem
Despite the saying <>, Mechnikov was forced to haul the theatrical props.
By the time he had finished percent of the task, the manager of the theater realized they did not have enough provision to feed the worker until he finished the work. Mechnikov ate percent of the received provision, with greater than .
That is when the manager, by slightly altering the popular motto <>, came up with <> (or almost nothing). For this reason, he decided to assign some free workforce to the toiling proletarian: a few coders who work for food. Each of the coders works times faster than the electrician and eats times slower.
The supply of free coders is virtually unlimited, but there is no reason to get too many of them. What if this becomes news and a great crowd of them arrives, craving free food? Help the manager to find the smallest necessary number of coders sufficient to make the available provision last until the work is finished.
Input
The first line of the input file contains a single number (), the number of tests. Each of the following lines of the input file contains four integers , denoting, correspondingly, the percentage of completed work, the percentage of consumed provision, and how many times faster a coder works, and how many times slower he eats. It is guaranteed that .
Output
As an answer to each of tests, print a single integer: the minimum number of coders necessary to do the job. If it is impossible to complete the work, print -1.