collections.Counter()

  • + 2 comments

    > Easy to do

    from collections import Counter
    input() # we don't need to store this input
    l = list(map(int, input().split()))
    # conter to dict Object
    cnt = Counter(l)
    # Initial price is zero
    ans = 0 
    for i in range(int(input())):
        size , price = [int(i) for i in input().split()]
        if cnt[size] > 0:
            ans += price
            cnt.subtract({size:1}) # subtract by 1
    print(ans)