All submissions for this problem are available.
Let us play a game of cards. As you all know there are 52 cards in a regular deck, but our deck is somewhat different. Our deck consists of N cards. Each card simply contains a unique number from 1 to N. Initially all the cards are kept on the table, facing up. Rob, the notorious kid, flipped some of the cards, i.e. made them face down. Now, your task is to print any valid sequence of magic operations (as defined below) such that after a maximum of K magic operations, all the cards are facing upwards only.
A magic operation on card at position i consists of flipping its direction from up to down and vice versa. Also, if there exists a card on its right side, i.e. at position (i+1), that is also flipped.
Print the index of the cards that you are going to perform the magic operation on.
Input consists of 2 lines. The first line contains 2 integers N and K, denoting the number of cards in our deck and the maximum possible number of moves allowed.
The second line contains N integers, whose absolute value lies from 1 to N. If a number is less than 0, it is initially facing down, else it is facing upwards.
It is guaranteed that all the absolute values on the cards are unique.
Output on the first line an integer X, denoting the number of operations you intend to make for making all the cards face upwards. This integer should be less than or equal to K.
On the next line of the output, print X space separated integers, denoting the order in which you want to carry on the magic operations on any of the N cards.
Note: You have to print the index of the cards that you are going to perform the magic operation on.
If there exist multiple solutions, output any of them
1 ≤ N ≤ 1000
N ≤ K ≤ max(5000, N * N)
Sample Input 0
3 4 1 2 3
Sample Output 0
All the cards are already facing up.
Sample Input 1
5 12 4 -2 3 -1 5
Sample Output 1
2 2 3
Below sequence shows the cards after every magic operation:
t = 0, 4 -2 3 -1 5 t = 1, 4 2 -3 -1 5 t = 2, 4 2 3 1 5
Finally all the cards are now facing upwards and the number of steps are also less than k i.e. 12.
|Tags||icl2017, likecs, likecs, looping|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, 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, SCM chicken, CLOJ, FS|
Fetching successful submissions