Calculate cost of right half
height = tot [ max_ind ] - 1 NEW_LINE for x in range ( max_ind + 1 , N ) : NEW_LINE INDENT cost += arr [ x ] - height NEW_LINE if height > 0 : NEW_LINE INDENT height -= 1 NEW_LINE DEDENT DEDENT return cost NEW_LINE