Here cand and maxi arrays are in non - increasing order beforehand . Now , j is the index of the next cand element and i is the index of next maxi element . Traverse through maxi array . If cand [ j ] > maxi [ i ] insert cand [ j ] at the ith position in the maxi array and remove the minimum element of the maxi array i . e . the last element and increase j by 1 i . e . take the next element from cand .
k = len ( maxi ) NEW_LINE j = 0 NEW_LINE for i in range ( k ) : NEW_LINE INDENT if ( cand [ j ] > maxi [ i ] ) : NEW_LINE INDENT maxi . insert ( i , cand [ j ] ) NEW_LINE del maxi [ - 1 ] NEW_LINE j += 1 NEW_LINE DEDENT DEDENT