If arr [ i ] > arr [ j ] then ticket can be brought from counter [ j + 1 , N ]
if ( arr [ i ] > arr [ j ] ) : NEW_LINE INDENT ans = ans + min ( k , ( i - j ) ) * arr [ i ] NEW_LINE k = k - ( i - j ) NEW_LINE arr [ i ] -= 1 NEW_LINE DEDENT else : NEW_LINE