collections.Counter()

  • + 0 comments

    from collections import Counter

    X, shoe_sizes = input(), map(int, input().split())

    inventory = Counter(shoe_sizes) earning = 0

    for _ in range(int(input())): size, price = map(int, input().split()) if inventory[size]: inventory[size] -= 1 earning += price

    print(earning)