-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1966.py
More file actions
31 lines (28 loc) · 714 Bytes
/
1966.py
File metadata and controls
31 lines (28 loc) · 714 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
import collections
import heapq
import sys
n = int(sys.stdin.readline())
answer = []
for _ in range(n):
tn, fn = map(int,sys.stdin.readline().split())
l = list(map(int,sys.stdin.readline().split()))
que = collections.deque()
heap = []
result = 0
for i, ele in enumerate(l):
que.append((i,ele))
heapq.heappush(heap,-ele)
max = -heapq.heappop(heap)
while True:
popleft = que.popleft()
if popleft[1]==max:
result +=1
if popleft[0] == fn:
break
else:
max = -heapq.heappop(heap)
else:
que.append(popleft)
answer.append(result)
for ele in answer:
print(ele)