Skip to content

Instantly share code, notes, and snippets.

@Peelz
Last active April 5, 2020 04:16
Show Gist options
  • Save Peelz/c0e11275069bde2181ba21819d54bea2 to your computer and use it in GitHub Desktop.
Save Peelz/c0e11275069bde2181ba21819d54bea2 to your computer and use it in GitHub Desktop.
5
3
360 480
420 540
600 660
3
0 1440
1 3
2 4
5
99 150
1 100
100 301
2 5
150 250
2
0 720
720 1440
4
2 4
3 5
0 2
4 6
#!/usr/bin/env python
def assign_to(new_schedule, list_schedule):
new_start, new_end = new_schedule
result = None
if len(list_schedule):
for (i, v) in enumerate(list_schedule):
old_start, old_end = v
if len(list_schedule) == 1 and new_end <= old_start:
result = [new_schedule] + list_schedule
elif i == len(list_schedule) - 1 and new_start >= old_end:
result = list_schedule + [new_schedule]
elif new_start >= old_end and new_end <= list_schedule[i+1][0]:
result = list_schedule[:i - 1] + [new_schedule] + list_schedule[i:]
else:
continue
else:
result = [new_schedule]
return result
def main():
test_num = int(input())
for c_no in range(test_num):
schedule_num = int(input())
c = []
j = []
result = ""
failed = False
for _ in range(schedule_num):
v = input().split(" ")
if not failed:
new_min, new_max = v
insert_data = [int(new_min), int(new_max)]
_j = assign_to(insert_data, j)
if _j != None:
j = _j
result += "J"
else:
_c = assign_to(insert_data, c)
if _c != None:
result +="C"
c = _c
else:
result = "IMPOSSIBLE"
failed =True
# break
print("Case #%s: %s\n" % (c_no+1, result))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment