Enormous input runtime error

This is link to solution!!It compiles fine in my compiler but fails in codechef compiler!!!

Increase your array size first. Why is it only upto 30 when number of elements can be till 10^7?

Also, you dont need to verify n and k, they will be according to constraints