-
Notifications
You must be signed in to change notification settings - Fork 1
/
Paint the Wall.py
31 lines (26 loc) · 1.04 KB
/
Paint the Wall.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
"""
Formally, given a wall of infinite height, initially unpainted. There occur N operations, and in ith operation,
the wall is painted upto height Hi with color Ci. Suppose in jth operation (j>i) wall is painted upto height Hj with
color Cj such that Hj >= Hi, the Cith color on the wall is hidden. At the end of N operations, you have to find the number
of distinct colors(>=1) visible on the wall.
Help him find out the number of distinct colors on the wall.
"""
def main():
for i in range(0,int(input())):
n,m=list(map(int,input().split()))
h=list(map(int,input().split()))
c=list(map(int,input().split()))
j=h.index(max(h))
h=h[j:]
c=c[j:]
index=[]
new_c=[]
for j in range(0,len(h)):
for k in range(j+1,len(h)):
if h[j]<=h[k]:
break
else:
new_c.append(c[j])
print(len(list(set(new_c))))
if __name__=="__main__":
main()