collections.Counter()

  • + 0 comments
    from collections import Counter
    X = input() # number of shoes
    shoeSizes = Counter(list(map(int, input().split())))
    N = int(input())
    total = 0
    for _ in range(N):
        customer = list(map(int, input().split()))
        try:
            shoseSize = shoeSizes[customer[0]]
            if shoeSizes[customer[0]] > 0:
                total += customer[1]
                shoeSizes[customer[0]] -= 1
        except:
            pass
    
    print(total)