collections.Counter()

  • + 0 comments
    from collections import Counter
    
    x = int(input().strip())
    shoes = list(map(int, input().split()))
    shoe_counter = Counter(shoes)
    N = int(input().strip())
    
    revenue = 0
    
    for i in range(N):
        size, price = map(int, input().split())
        if shoe_counter[size] > 0:
            revenue+=price
            shoe_counter[size] -= 1
        elif shoe_counter[size] == 0:
            del shoe_counter[size]
            revenue +=0
    
    print(revenue)