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.
defluckBalance(k,contests):# Separate important and unimportant contestsimportant_contests=[luckforluck,importanceincontestsifimportance==1]unimportant_contests=[luckforluck,importanceincontestsifimportance==0]# Sort the important contests in descending order of luckimportant_contests.sort(reverse=True)# Calculate the total luck balancemax_luck=sum(unimportant_contests)# Add the luck from the top k important contests that Lena can losemax_luck+=sum(important_contests[:k])# Subtract the luck from the remaining important contests that Lena has to winmax_luck-=sum(important_contests[k:])returnmax_luck
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 →