Code Jam - Google’s Coding Competitions

how to approach the problem for test case 2.

You might find some useful comments about it here. Read the full blog. https://codeforces.com/blog/entry/71545