collections.Counter()

Sort by

recency

|

1426 Discussions

|

  • + 1 comment
    from collections import Counter 
    
    number_of_shoes = int(input())
    shoe_sizes = map(int, input().split())
    number_of_customers = int(input())
    
    shoe_stock = Counter(shoe_sizes)
    earned = 0
    for _ in range(number_of_customers):
        shoe_size, price = map(int, input().split())
        if shoe_stock[shoe_size]:
            shoe_stock[shoe_size] -= 1
            earned += price
        
    print(earned)
    
  • + 0 comments
    n_shoes=input()
    all_size=list(map(int,input().split()))
    n_costumers=int(input())
    customer_want = [tuple(map(int, input().split())) for _ in range(int(n_costumers))]
    
    gains=[]
    for custom in customer_want:
        if custom[0] in all_size:
            all_size.remove(custom[0])
            gains.append(custom[1])
            
    print(sum(gains))
    
  • + 1 comment
    x = int(input())
    shoeSize = list(map(int,input().split()))
    n = int(input())
    total=0
    for i in range(n):
        size,prize = map(int,input().split())
        if size in shoeSize:
            total +=prize
            shoeSize.remove(size)
    print(total)
    
  • + 0 comments
    from collections import Counter
    
    X = int(input()) # num of shoes
    shoe_stock = Counter(list(map(int,input().split(" "))))
    num_of_customers = int(input())
    earned = 0
    for i in range(num_of_customers):
        cust_size, cust_price = list(map(int,input().split(" ")))
        #if size is buyable then -1 to size and plus price
        if shoe_stock[cust_size]:
            shoe_stock[cust_size] -= 1
            earned += cust_price
    print(earned)
    
  • + 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)