each progression you pick some integer k>0, take the top k cards from the first deck and submit them, in the request they are presently, on top of the new deck. You play out this activity until the first deck is vacant. (Allude to the notes area for the better arrangement.) We should characterize a request for a deck as ∑i=1nnn−i⋅pi.
Correct answer will be upvoted else downvoted. Computer science.
In each progression you pick some integer k>0, take the top k cards from the first deck and submit them, in the request they are presently, on top of the new deck. You play out this activity until the first deck is vacant. (Allude to the notes area for the better arrangement.)
We should characterize a request for a deck as ∑i=1nnn−i⋅pi.
Given the first deck, output the deck with greatest conceivable request you can make utilizing the activity above.
Input
The main line contains a solitary integer t (1≤t≤1000) — the number of experiments.
The principal line of each experiment contains the single integer n (1≤n≤105) — the size of deck you have.
The subsequent line contains n integers p1,p2,… ,pn (1≤pi≤n; pi≠pj if i≠j) — upsides of card in the deck from base to top.
It's dependable that the amount of n over all experiments doesn't surpass 105.
Output
For each experiment print the deck with most extreme conceivable request. Print upsides of cards in the deck from base to top.
In case there are numerous replies, print any of them
Step by step
Solved in 4 steps with 1 images