collections.Counter()

Sort by

recency

|

1419 Discussions

|

  • + 0 comments
    from collections import Counter
    
    number_of_shoes: int = int(input())
    shoes_sizes_availability: Counter[int] = Counter(map(int, input().split()))
    
    number_of_customers: int = int(input())
    
    earnings: int = 0
    
    for _ in range(number_of_customers):
        size, price = map(int, input().split())
        if shoes_sizes_availability[size] > 0:
            earnings += price
            shoes_sizes_availability[size] -= 1
    
    print(earnings)
    
  • + 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)
    
  • + 0 comments
    from collections import Counter
    X = int(input())
    myList = list(map(int, input().split()))
    shoes = dict(Counter(myList))
    N = int(input())
    earnings = 0
    for i in range(N):
        size, price = map(int,input().split())
        try:
            if shoes[size] > 0:
                shoes[size] -= 1
                earnings += price
        except KeyError:
            pass
    print(earnings)
    
  • + 0 comments
    from collections import Counter
    
    X = int(input())
    sizes = Counter(list(map(int, input().split(' '))))
    N = int(input())
    earning = 0
    
    for i in range(N):
        size, price = map(int, input().split(' '))
        if sizes[size] > 0:
            sizes[size] -= 1
            earning += price    
        else:
            earning += 0
    
    print(earning)
    
  • + 0 comments
    from collections import Counter
    
    x = int(input())
    size = list(map(int, input().split()))
    size_count = Counter(size)
    cus = int(input())
    total = 0
    for _ in range(cus):
        s, cost = map(int,input().split())
        if size_count[s] > 0:       # if stock available
            size_count[s] -= 1   
            total += cost
    print(total)