GUPTA MECHANICAL

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

Sunday, 10 July 2022

[Solution] Equate Multisets Codeforces Solution



F. Equate Multisets
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Multiset —is a set of numbers in which there can be equal elements, and the order of the numbers does not matter. Two multisets are equal when each value occurs the same number of times. For example, the multisets {2,2,4} and {2,4,2} are equal, but the multisets {1,2,2} and {1,1,2} — are not.

You are given two multisets a and b, each consisting of n integers.

In a single operation, any element of the b multiset can be doubled or halved (rounded down). In other words, you have one of the following operations available for an element x of the b multiset:

  • or replace x with x2,
  • or replace x with x2 (round down).

Note that you cannot change the elements of the a multiset.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

See if you can make the multiset b become equal to the multiset a in an arbitrary number of operations (maybe 0).

For example, if n=4a={4,24,5,2}b={4,1,6,11}, then the answer is yes. We can proceed as follows:

Input

The first line of input data contains a single integer t (1t104) —the number of test cases.

Round Down the Price Codeforces Solution

Polycarp Writes a String from Memory Codeforces Solution

Train and Queries Codeforces Solution

Not a Cheap String Codeforces Solution

Split Into Two Sets Codeforces Solution

Equate Multisets Codeforces Solution

Passable Paths (easy version) Codeforces Solution

Passable Paths (hard version) Codeforces Solution

Each test case consists of three lines.

The first line of the test case contains an integer n (1n2105) —the number of elements in the multisets a and b.

The second line gives n integers: a1,a2,,an (1a1a2an109) —the elements of the multiset a. Note that the elements may be equal.

The third line contains n integers: b1,b2,,bn (1b1b2bn109) — elements of the multiset b. Note that the elements may be equal.

It is guaranteed that the sum of n values over all test cases does not exceed 2105.

Output

For each test case, print on a separate line:

  • YES if you can make the multiset b become equal to a,
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEsyesYes and YES will be recognized as positive answer).

No comments:

Post a Comment