Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Team Play by rybld2
from typing import List
def max_score_simplified(cut: List[int], bend: List[int], k: int) -> int:
"""the case k = 1 is easy. if k is greater, take the first one and
start again with the remaining sublist by decreasing k by 1"""
diff = sorted([(cut[i] - bend[i], i) for i in range(len(cut))], reverse=True)
del bend[diff[0][1]]
if k==1 : return cut[diff[0][1]]+ sum(bend)
res=cut.pop(diff[0][1])
return res+ max_score_simplified(cut, bend, k-1)
def max_score(cut: List[int], bend: List[int], k: int) -> int:
if k == 0: return sum(bend)
if k == len(cut): return sum(cut) #These 2 lines are not necessary but avoid calculations
if k > len(cut) // 2: #Choosing k elements is also choosing the others. Let's do less calculations
cut, bend = bend, cut
k = len(cut) - k
return max_score_simplified(cut, bend, k)
Dec. 24, 2020
Comments: