-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCOKE.py
More file actions
31 lines (29 loc) · 760 Bytes
/
COKE.py
File metadata and controls
31 lines (29 loc) · 760 Bytes
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
test_case = int(input())
for test in range(test_case):
(n, m, k, l, r) = map(int, input().split())
c = []
p = []
for i in range(n):
(a, b) = map(int, input().split())
c.append(a)
p.append(b)
isSolExist = False
sol_list = []
for i in range(n):
final_temp = c[i]
if c[i] < k:
final_temp = c[i] + m
if final_temp > k:
final_temp = k
if c[i] > k:
final_temp = c[i] - m
if final_temp < k:
final_temp = k
if r >= final_temp >= l:
isSolExist = True
sol_list.append(p[i])
if len(sol_list) == 0:
print(-1)
else:
sol_list.sort()
print(sol_list[0])