collections.Counter()

  • + 0 comments
    from collections import Counter
    
    
    n_shoes = int(input())
    sizeList = input().split(' ')
    sizeCounter = Counter(sizeList)
    n_customer = int(input())
    sum_ = 0
    for _ in range(n_customer):
        desire_list = input().split(' ')
        if desire_list[0] in sizeCounter.keys() and sizeCounter[desire_list[0]] != 0:
            sum_ += int(desire_list[1])
            sizeCounter[desire_list[0]] -=1
    print(sum_)