collections.Counter()

Sort by

recency

|

1423 Discussions

|

  • + 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)
    
  • + 0 comments

    my code without using any imports or libraries

    x = int(input())

    shoeSize = list(map(int, input().split()))

    n = int(input())

    total = 0

    if (0 < x < 10**3) or (0 < n <= 10**3) or (20 < x_i < 100) or (2 < shoeSize < 20): for _ in range(n): size, price = map(int, input().split()) if size in shoeSize: total += price shoeSize.remove(size) print(total)

  • + 0 comments
    from collections import Counter
    
    num_shoes = int(input())
    size_inventory = Counter(int(x) for x in input().split())
    num_customers = int(input())
    
    customer_orders = []
    profit = 0
    
    for i in range(num_customers):
        customer_orders.append(tuple(int(x) for x in input().split()))
    
    for (size, price) in customer_orders:
        if size_inventory[size] > 0:
            size_inventory[size] -= 1
            profit += price
    
    print(profit)
    
  • + 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)