• + 0 comments

    def luckBalance(k, contests): important = [luck for luck, importance in contests if importance == 1] unimportant = [luck for luck, importance in contests if importance == 0]

    # Sort important contests in descending order of luck
    important.sort(reverse=True)
    
    # Sum luck from the k most important contests and subtract the rest
    return sum(important[:k]) - sum(important[k:]) + sum(unimportant)