Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- input_lines = """
- 4 6
- 1 3 2
- 7 13 10
- 18 20 13
- 3 4 2
- 0
- 1
- 2
- 3
- 5
- 8
- """.split("\n")[1:-1]
- construction_num, person_num = map(int, input_lines[0].split())
- input_lines = input_lines[1:]
- class Construction:
- def __init__(self, start, end, pos):
- self.start = start
- self.end = end
- self.pos = pos
- self.start_pos = start - pos
- self.end_pos = end - pos
- class Constructions:
- def __init__(self):
- self.list = []
- def append(self, construction):
- self.list.append(construction)
- def sort(self):
- self.list = sorted(self.list, key=lambda x:x.start_pos)
- def encounter(self, p_pos):
- li = [c.pos for c in self.list if c.start_pos <= p_pos and p_pos < c.end_pos]
- if len(li) > 0:
- return min(li)
- else:
- return -1
- def __str__(self):
- return str([(c.start_pos, c.end_pos) for c in self.list])
- class Person:
- def __init__(self, departure):
- self.departure = departure
- class Persons:
- def __init__(self):
- self.list = []
- def append(self, person):
- self.list.append(person)
- constructions = Constructions()
- for index, line in enumerate(input_lines):
- if index < construction_num:
- start, end, pos = map(int, line.split())
- c = Construction(start, end, pos)
- constructions.append(c)
- input_lines = input_lines[construction_num:]
- persons = Persons()
- for line in input_lines:
- departure = int(line)
- p = Person(departure)
- persons.append(p)
- constructions.sort()
- for p in persons.list:
- print(constructions.encounter(p.departure))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement