Last active
May 15, 2023 19:57
-
-
Save maestroviktorin/bbc226f87729488268a2d990b3e0d42b to your computer and use it in GitHub Desktop.
Solution to the problem #7709 from kompege.ru
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Problem No. 7709 on https://www.kompege.ru | |
def does_not_intercept(pair_a: tuple[int, int], pair_b: tuple[int, int]) -> bool: | |
return all(x < pair_b[0] for x in pair_a) or all(x > pair_b[1] for x in pair_a) | |
with open('26_7709.txt') as file: | |
rows = file.readlines() | |
K = int(rows[0]) | |
N = int(rows[1]) | |
clients = (tuple(int(x) for x in row.split()) for row in rows[2:]) | |
barbers = {x: list() for x in range(1, K + 1)} | |
appointments = list() | |
for client in clients: | |
for barber in sorted(barbers.keys()): | |
if not barbers[barber] or all(does_not_intercept(client, previous_client) for previous_client in barbers[barber]): | |
barbers[barber].append(client) | |
appointments.append(barber) | |
break | |
print(len(appointments), appointments[-2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment