Codechef -- King of the Ring

Problem Link 

Solution :