GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 2 October 2022

[Solution] Pebbles and Beads Codeforces Solution



F. Pebbles and Beads
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are two currencies: pebbles and beads. Initially you have a pebbles, b beads.

There are n days, each day you can exchange one currency for another at some exchange rate.

On day i, you can exchange pixpi pebbles for qiyqi beads or vice versa. It's allowed not to perform an exchange at all. Meanwhile, if you perform an exchange, the proportion xqi=ypi 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 n problems independently: for each day i, output the maximum number of pebbles that you can have at the end of day i if you perform exchanges optimally.

Input

The first line of the input contains a single integer t (1t103) — the number of test cases. The description of test cases follows.

The first line of each test case contains three integers na and b (1n3000000a,b109) — the number of days and the initial number of pebbles and beads respectively.

The second line of each test case contains n integers: p1,p2,,pn (1pi109).

The third line of each test case contains n integers: q1,q2,,qn (1qi109).

It is guaranteed that the sum of n over all test cases doesn't exceed 300000.

Output

Output n 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 106.

Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if |ab|max(1,|b|)106.

No comments:

Post a Comment