collections.Counter()

  • + 0 comments

    For Python3 Platform

    import collections
    
    X = int(input())
    shoe_sizes = list(map(int, input().split()))
    shoefreq_list = dict(collections.Counter(shoe_sizes))
    
    N = int(input())
    total_amount = 0
    
    for i in range(N):
        shoe_size, price = map(int, input().split())
        
        if(shoe_size in shoefreq_list.keys() and shoefreq_list[shoe_size] > 0):
            total_amount += price
            shoefreq_list[shoe_size] -= 1
    
    print(total_amount)