Playing with cards

Why my testcase 0 and testcase 1 showing wrong answer?

Consider input:
5 2
1 2 3 4 5
Expected Output:
2
4
3
5
1
Your o/p:
4
1
2
3
5

Refer the approach and the logic from here: Playing with cards

Refer this implementation: https://ide.codingblocks.com/s/246613