find the smallest partial sum modulo P that is at least K.

Here is the link to the problem-: BESTSUM Problem - CodeChef
I am trying to understand the concept used in the Submissions. I am not able to get it. Need help!