forked from anoubhav/Coursera-Algorithmic-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4.5 lottery.py
53 lines (24 loc) · 812 Bytes
/
4.5 lottery.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# python3
""" Task: You are given a set of points on a line and a set of segments on a line. The goal is to compute, for each point, the number of segments that contain this point """
# Inputs
master_list = list()
s, p = [int(i) for i in input().split()]
for i in range(s):
a, b = [int(i) for i in input().split()]
master_list.append((a,'l'))
master_list.append((b,'r'))
points = input().split()
for i in points:
master_list.append((int(i),'p'))
master_list.sort()
segment_count = 0
point_segment_map = dict()
for i in master_list:
if i[1] == 'l': segment_count += 1
elif i[1] == 'r': segment_count -= 1
else:
point_segment_map[i[0]] = segment_count
temp = ''
for i in points:
temp += str(point_segment_map[int(i)]) + ' '
print(temp[:-1])