collections.Counter()

  • + 0 comments

    Without using the Counter:

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    num_shoes = int(input())
    shoes = list(map(int, input().split(' ')))
    
    sizes = {}
    # build shoe sizes dictionary
    for i in shoes:
        if i in sizes:
            sizes[i] += 1
        else:
            sizes[i] = 1
            
    num_customers = int(input())
    
    customers = []
    profit = 0
    
    for i in range(num_customers):
        size, cash = map(int, input().split(' '))
        if size in sizes:
            if sizes[size] != 0:
                profit += cash
                sizes[size] -= 1
            
    print(profit)