Eventually, I have got AC, but I think that the problem is very likely to be incorrect. It has a low accepted rate (for a relatively easy problem), and there are no constraints on K, P and Ai. I assumed them to be long longs, but I got AC after changing them to ints! The other parts of the code are exactly the same. Check out my submissions: CodeChef: Practical coding for everyone (WA) and CodeChef: Practical coding for everyone (AC). It seems that there is an overflow in tests.
Hopefully, this problem will be corrected or removed. At least someone struggling with the problem could find this post
I am so sorry @karolis_kusas , I think I didnt even reply to your previous thread. We all really appreciate that you report such bugs- and I report it to @admin who gets it fixed within a day (be it weak test cases, or unclear problem statement).
Currently @admin is busy dealing with ICPC, its ranklist ,plagiarism checking and addressing the issues cropped during the contest. Please wait just till they publish the results- once she is free to breathe again, I will find a suitable time to give additional work to her :3 XDXDXD.
But in all seriousness, I am sorry for the delay. Just let them get a little relaxed from ICPC, they will be free to hear all queries then