Skip to main content

Posts

Frog Sort codechef February 2021 long challenge editorial

   Frog Sort codechef February 2021  long challenge editorial - There are  N N  frogs (numbered  1 1  through  N N ) in a line. For each valid  i i , the  i i -th frog is initially at the position  i i , it has weight  W i W i , and whenever you hit its back, it jumps a distance  L i L i  to the right, i.e. its position increases by  L i L i . The weights of the frogs are pairwise distinct. You can hit the back of each frog any number of times (possibly zero, not necessarily the same for all frogs) in any order. The frogs do not intefere with each other, so there can be any number of frogs at the same time at each position. Your task is to sort the frogs in the increasing order of weight using the smallest possible number of hits. In other words, after all the hits are performed, then for each pair of frogs  ( i , j ) ( i , j )  such that  W i < W j W i < W j , the position of the  i i -th frog should be strictly smaller than the position of the  j j -th frog. Find the smalle