-
Notifications
You must be signed in to change notification settings - Fork 110
/
solution.py
30 lines (23 loc) · 835 Bytes
/
solution.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
#!/usr/bin/env python3
# main module
if __name__ == "__main__":
# input number and queries
n, q = [int(x) for x in input().strip().split()]
# input n integer sequence
arr = [int(x) for x in input().strip().split()]
for _ in range(q):
# input integer of each query
d = int(input().strip())
maxes = []
was_first = False
# print the answer to each query
for i in range(n - d + 1):
if i == 0 or was_first == True:
maxes.append(max(arr[i:i+d]))
else:
maxes.append(max(maxes[-1], arr[i+d-1]))
if maxes[-1] == arr[i]:
was_first = True
else:
was_first = False
print(min(maxes))