Choosing sides solution in Clear category for Team Play by HeNeArKr
# When assigning robots to tasks, prioritize those robots with the largest
# difference in their bending and cutting abilities.
from typing import List
def max_score(cut: List[int], bend: List[int], k: int) -> int:
"""Return maximum possible score when 'k' robots are assigned to cutting.
maxim = (len(cut)-k, k) # (benders, cutters)
count = [0, 0]
total = 0
# (difference, [bigger num, smaller num], True if 2nd num is bigger)
vals = [(abs(b-c), [b, c][::1-2*(c > b)], c > b)
for (b, c) in zip(bend, cut)]
for _, nums, side in sorted(vals, reverse=True):
# this section would be easier to read if implemented with a simple
# 'if else' operation, but a little more repetitive.
switch = not count[side] < maxim[side]
total += nums[switch]
# exclusive or
count[(not switch and side) or (switch and not side)] += 1
May 27, 2020