All submissions for this problem are available.
Fancyland is a land of peace. N People living there are peaceful and there housing colony are in a sequential manner. People of Fancyland have some K amount power.
But with changing time most powerful person Anurag and second most powerful Jayesh became selfish.
Now they both want to kill each other. .
Seeing this the king of Fancyland Ankit immediately ordered to shift their houses as far as possible. Since Anurag has more power, he prefers to be on the right side of the colony.
Both Jayesh and Anurag have the talent to convince people and change their mind to join them and form a group to have a war.
Both the groups under all circumstances have equal number of members in their group with their respective powers. Since Both Anurag and Jayesh wants to be as close as possible so that they can fight hence they one by one exchange their houses with people whom they have convinced. Note that they can convince only their neighbours.
Both Jayesh and Anurag arrange their group members in such a manner that the person possesing highest power in the group lives adjacent to them and then second highest
member next and so on and then they start convincing other new neighbour.
Seeing their convincing talent King decided to form a peace making commitee which has more or equal number of members than the members in conflicting groups(excluding Anurag and Jayesh),
so that no war occurs.
Peace making commitee also comprises of citizens from the very same Fancyland. King Ankit gives them special techniques to prevent war,
thus commitee members give away their personal powers and now their power K is 0.
First input is number of test cases T.
In every test case first line contains number of people living in Fancyland.
Next line contains N space seperated integers which denotes the power K of the person living their.
Output the array showing the situation where all conditions are met and if one more person is convinced by the groups war will occur..
- 1 ≤ T ≤ 20
- 3 ≤ N ≤ 100000
- 1 ≤ k ≤ 100000
Input: 2 10 1 2 3 4 5 6 7 8 9 10 5 78 35 66 12 88 Output: 1 2 9 0 0 0 0 10 8 7 35 78 0 88 12
|Time Limit:||0.126582 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.