I can try! I can sort!

Fellow_junior Unlock The Algorithm, Spr...
Limits 1s, 256 MB

Let me tell you a heartwarming tale of a sweet little boy named Arham. Everyone who saw him adored him, but his dear grandmother especially did. She cherished him more than anything and would do anything to make him happy. Once, she gifted him a delightful set of balls and rattles. The rattles were tinier than the balls but just as charming. One day, he stumbled upon a magical forest with his trusty toys by his side. However, as he explored the enchanting surroundings, he realized he needed to find his way.

Despite his best efforts, he was unable to navigate his way out. As he strolled down the path, feeling discouraged by his lack of progress, a wise-looking gentleman with a magnificent, flowing gray beard appeared before him.

With a mysterious glint in his eye, the stranger proposed a challenge - "I can guide you to the exit," he said, "but only if you can arrange your toys neat and orderly. Line them up from largest to smallest, and I will see if you are up to the task."

Let's help Arham sort through his toys and get him back home.


The input consists of multiple test cases. The first line contains an integer t(1t100)t(1 \le t \le 100) — the number of test cases. The description of the tt test cases follows.

The first line of each test case contains two positive integers nn and mm (0n,m106;1n+m106)(0\le n,m \le 10^{6} ; 1 \le n+m \le 10^{6}) — the number of balls and rattles, respectively.

The second line of each test case contains nn integers a1,a2,a3.,ana_1 ,a_2,a_3….,a_n(0ai106)(0 \le a_i \le 10^{6})— the size of each set of balls.

The next line of each test case contains mm integers b1,b2,b3.,bnb_1,b_2,b_3….,b_n (0bi106)(0 \le b_i \le 10^{6})— the size of each set of rattles.

It is guaranteed that the sum of nn and mm over all test cases does not exceed 10610^{6}.


For each test case, output all sets of balls and rattles together where they should be lined up from largest to smallest according to the size of the set.


2 3
1 6
2 3 7
3 3
6 3 1
9 7 2
7 6 3 2 1
9 7 6 3 2 1


Login to submit.


47% Solution Ratio
rafiwho.017313Earliest, 4M ago
rafiwho.017313Fastest, 0.2s
jahid_hridoyLightest, 5.4 MB
s_anikShortest, 391B
Toph uses cookies. By continuing you agree to our Cookie Policy.