Playing with cards

https://hack.codingblocks.com/contests/c/537/493

how to approach this question??