How to solve this...? I tried but couldnt solve

How to optimize this ??
I am getting TLE

The Minimum Number Of Moves

Problem Code: SALARY

My code
https://www.codechef.com/viewsolution/42861356

Here’s the editorial:

1 Like

thanks

1 Like