Recently I was solving the problem in a recent contest i.e **NPL Qualifier 2019**, and I am not able to come up with the logic of comparator for sorting the data?

Can anyone tell me the logic for writing the comparator, how do you come up with that logic, I am interested in the thought process?

Problem Link: Amplication

My Solution Link: https://www.codechef.com/viewsolution/27528903

**I got WA for my submissions.**

Thanks