[Solution] Pebbles and Beads Codeforces Solution
There are two currencies: pebbles and beads. Initially you have pebbles, beads.
There are days, each day you can exchange one currency for another at some exchange rate.
On day , you can exchange pebbles for beads or vice versa. It's allowed not to perform an exchange at all. Meanwhile, if you perform an exchange, the proportion must be fulfilled. Fractional exchanges are allowed.
You can perform no more than one such exchange in one day. The numbers of pebbles and beads you have must always remain non-negative.
Please solve the following problems independently: for each day , output the maximum number of pebbles that you can have at the end of day if you perform exchanges optimally.
The first line of the input contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains three integers , and (, ) — the number of days and the initial number of pebbles and beads respectively.
The second line of each test case contains integers: ().
The third line of each test case contains integers: ().
It is guaranteed that the sum of over all test cases doesn't exceed .
Output numbers — the maximum number of pebbles at the end of each day.
Your answer is considered correct if its absolute or relative error does not exceed .
Formally, let your answer be , and the jury's answer be . Your answer is accepted if and only if .
No comments:
Post a Comment