We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
from collections import Counter
X=int(input())
S=list(map(int,input().strip().split()[:X]))
N=int(input())
lst=[]
for i in range(0,N):
lst.append(list(map(int,input().strip().split()[:2])))
C=Counter(S)
ttl=0
for i in range(0,N):
a,b=lst[i]
if a in C and C[a]>0:
ttl+=b
C[a]-=1
print(ttl)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
collections.Counter()
You are viewing a single comment's thread. Return to all comments →
from collections import Counter X=int(input()) S=list(map(int,input().strip().split()[:X])) N=int(input()) lst=[] for i in range(0,N): lst.append(list(map(int,input().strip().split()[:2]))) C=Counter(S) ttl=0 for i in range(0,N): a,b=lst[i] if a in C and C[a]>0: ttl+=b C[a]-=1 print(ttl)