collections.Counter()

  • + 0 comments

    Way 1

    from collections import Counter
    
    X = int(input())
    shoe_sizes = Counter(map(int,input().split()))
    N = int(input())
    total_price = 0
    for i in range(N):
        size, price = list(map(int,input().split()))
        if shoe_sizes[size] !=0:
            total_price+= price
            shoe_sizes[size] -= 1
            
    print(total_price)
    

    Way 2

       X = int(input())
    shoe_sizes = list(map(int,input().split()))
    
    unique = set(shoe_sizes)
    count_dict = {size: 0 for size in unique}
    
    for shoe_size in shoe_sizes:
        count_dict[shoe_size] +=1
    
    N = int(input())
    total_price = 0
    for i in range(N):
        size, price = list(map(int,input().split()))
        if size in count_dict.keys():
            if count_dict[size] !=0:
                total_price+= price
                count_dict[size] -= 1
            
    print(total_price)