We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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)
Cookie support is required to access HackerRank
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 →
def luckBalance(k, contests): important = [luck for luck, importance in contests if importance == 1] unimportant = [luck for luck, importance in contests if importance == 0]