forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZCO12002.py
74 lines (48 loc) · 1.3 KB
/
ZCO12002.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from sys import stdin,stdout
def upper_bound(num,exit):
l = 0
r = len(exit)-1
temp = None
while l < r:
mid = (l+r)//2
if exit[mid] == num:
return exit[mid]
elif exit[mid] > num:
temp = exit[mid]
r = mid
else:
l = mid+1
if exit[r] >= num:
return exit[r]
return temp
def lower_bound(num,entry):
l = 0
r = len(entry)-1
temp = None
while l < r:
mid = (l + r) // 2
if entry[mid] > num:
r = mid
elif entry[mid] == num:
return entry[mid]
else:
temp = entry[mid]
l = mid+1
if entry[l] <= num:
return entry[l]
return temp
num_contests,num_entry,num_exit = map(int,stdin.readline().split())
contests = []
for c in range(num_contests):
v,w = map(int,stdin.readline().split())
contests.append([v,w])
entry = sorted(list(map(int,stdin.readline().split())))
exits = sorted(list(map(int, stdin.readline().split())))
max_tym = float('inf')
for con in range(num_contests):
temp1 = upper_bound(contests[con][1],exits)
temp2 = lower_bound(contests[con][0],entry)
if temp1 and temp2:
if (temp1 - temp2) + 1 < max_tym:
max_tym = (temp1 - temp2) + 1
print(max_tym)