codyssi2025/problem3.py

27 lines
586 B
Python

my_input = open("inputs/input3", "r").read().splitlines()
p1 = 0
p2 = 0
p3 = 0
last_boxes = set()
for line in my_input:
left, right = line.split(" ")
l_low, l_high = map(int, left.split("-"))
r_low, r_high = map(int, right.split("-"))
p1 += l_high - l_low + 1
p1 += r_high - r_low + 1
this_box_set = set(range(l_low, l_high + 1))
this_box_set |= set(range(r_low, r_high + 1))
p2 += len(this_box_set)
if len(this_box_set | last_boxes) > p3:
p3 = len(this_box_set | last_boxes)
last_boxes = this_box_set
print(p1)
print(p2)
print(p3)