Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created November 17, 2022 14:48
Show Gist options
  • Save mvallebr/c5c926cf80a7504d359b69c3c437c62a to your computer and use it in GitHub Desktop.
Save mvallebr/c5c926cf80a7504d359b69c3c437c62a to your computer and use it in GitHub Desktop.
def minimum_cost_array(red, blue, blue_cost):
assert len(red) == len(blue), f"red and blue lines have different sizes"
result = [0]
is_blue = False
for r, b in zip(red, blue):
cost_blue = b if is_blue else b + blue_cost
cost_red = r
if cost_blue <= cost_red:
is_blue = True
result.append(result[-1] + cost_blue)
else:
is_blue = False
result.append(result[-1] + cost_red)
return result
red = [2,3,4]
blue = [3,1,1]
blue_cost = 2
actual = minimum_cost_array(red, blue, blue_cost)
expected = [0, 2, 5, 6]
assert actual == expected, f"{actual} != {expected}"
print("ok")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment