Gopal and his Task
All submissions for this problem are available.
Gopal obviously is the leader of the class.His class mates are standing in line.His teacher has
assigned him the task of arranging the students , into ascending order
of their heights.But unfortunately ,Gopal knows only one thing, select k consecutive students, reverse their order. Finally, he wants their
heights to be in the sequence of ascending order. Gopal wonders what
is the fewest number of moves necessary to do his task successfully,
or print -1 if it's not possible.
First line contains t number of test cases.In each test case, first line contains n number of students and k. Next line contains n space seperated initial line with their heights.Output:
t lines containg minimum number of moves to complete the task.-1 if not possible.Constraints: 1<= t <=10 1<= n <=10 1<= k <=n Sample Input : 4 3 3 1 2 3 3 3 3 2 1 5 2 5 4 3 2 1 5 4 3 2 4 1 5 Sample Output : 0 1 10 -1
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, RUBY, ADA, BF, ASM, BASH|
Fetching successful submissions
If you are still having problems, see a sample solution here.