collections.Counter()

  • + 0 comments

    from collections import Counter

    def calc_earnings(shoes, customers):

    earnings = 0
    
    for c in customers:
        if c[0] not in shoes: continue
    
        shoes[c[0]] -= 1
        earnings += c[1]
    
        if (shoes[c[0]] <= 0): del shoes[c[0]]
    
    print(earnings)
    

    if name=='main':

    input() # We really don't use this info (number of shoes).
    shoes = Counter(map(int, input().split()))
    n = int(input())
    
    customers = []
    
    for _ in range(n):
        shoe_size, price = map(int, input().split())
        customers.append((shoe_size, price))
    
    calc_earnings(shoes, customers)