You are viewing a single comment's thread. Return to all comments →
Implemented as readable Python2:
def luckBalance(k, contests): heap = [] heapq.heapify(heap) luck = 0 for L,T in contests: if not T: luck = luck + L elif k < 1: luck = luck - L elif len(heap) < k: heapq.heappush(heap, L) else: luck = luck - heapq.heappushpop(heap, L) return luck + sum(heap)
Seems like cookies are disabled on this browser, please enable them to open this website
Luck Balance
You are viewing a single comment's thread. Return to all comments →
Implemented as readable Python2: