collections.Counter()

  • + 0 comments
    from collections import Counter
    
    if __name__ == "__main__":
        X = map(int, input())
        sizes = list(map(int, input().split()))
        N = int(input())
        demand = [list(map(int, input().split())) for i in range(N)]
        
        income = 0
        sizes = Counter(sizes)
        for size,price in demand:
            if sizes[size] != 0:
                income += price
                sizes[size] -= 1
        print(income)