collections.Counter()

Sort by

recency

|

1401 Discussions

|

  • + 0 comments
    import collections as c
    
    x = int(input())
    available_sizes= input()
    no_of_customers= int(input())
    
    cutomer_and_shoe_price_list= []
    
    for cutomer_shoe_price in range(no_of_customers):
        cutomer_and_shoe_price = input()
        cutomer_and_shoe_price_list.append(cutomer_and_shoe_price.split(" "))
    
    available_sizes_list= [i for i in available_sizes.split(" ")]
    # print(available_sizes_list)
    available_sizes_list_count= c.Counter(available_sizes_list)
    # print(available_sizes_list_count)  # Counter({'5': 2, '6': 2, '2': 1, '3': 1, '4': 1, '8': 1, '7': 1, '18': 1})
    
    # print(cutomer_and_shoe_price_list) # [['6', '55'], ['6', '45'], ['6', '55'], ['4', '40'], ['18', '60'], ['10', '50']]
     
    
    price_list= []
    
    for keys, values in available_sizes_list_count.items():
        for i in cutomer_and_shoe_price_list:
            if i[0] == keys:
                values= values - 1
                price_list.append(i[1])
                if values == 0:     # Prevents overselling
                    break
                
        # print(keys, values)
    print(sum(list(map(int, price_list))))
        
    
  • + 0 comments
    from collections import Counter
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    x = int(input())
    sizes = map(int, input().split())
    n = int(input())
    avail = Counter(sizes)
    sales = 0
    for i in range(n):
        order = list(map(int, input().split()))
        size = order[0]
        if size in avail.keys() and avail[size] > 0:
            sales += order[1]
            avail[size] -= 1
    
    print(sales)
    
  • + 0 comments

    from collections import Counter list1 = [] def test(customer_shoe_size,price): if customer_shoe_size in shoe_sizes.keys(): value = shoe_sizes.get(customer_shoe_size) shoe_sizes.subtract([customer_shoe_size]) if value > 0: list1.append(int(price))

    def sum_(): final = list(map(int,list1)) print(sum(final))

    if name == "main": global shoe_sizes no_of_shoes = int(input()) shoe_sizes = Counter((map(str,input().split()))) no_of_customers = int(input()) for i in range(no_of_customers): customer_shoe_size , price = input().split() test(customer_shoe_size,price) sum_()

  • + 0 comments

    X = int(input()) tot_inv = list(map(int, input().split()))

    from collections import Counter

    inventory = Counter(tot_inv)

    N = int(input())

    raghu_earn = 0

    for _ in range(N):

    size_price = input().split()
    size = int(size_price[0])
    price = int(size_price[1])
    
        if inventory[size]>0:
        raghu_earn+=price
        inventory[size]-=1
    

    print(raghu_earn)

    if inventory[size]>0:
        raghu_earn+=price
        inventory[size]-=1
    

    print(raghu_earn)

  • + 0 comments

    from collections import Counter

    def calc_earnings(shoes, customers):

    earnings = 0
    
    for c in customers:
        if c[0] not in shoes: continue
    
        shoes[c[0]] -= 1
        earnings += c[1]
    
        if (shoes[c[0]] <= 0): del shoes[c[0]]
    
    print(earnings)
    

    if name=='main':

    input() # We really don't use this info (number of shoes).
    shoes = Counter(map(int, input().split()))
    n = int(input())
    
    customers = []
    
    for _ in range(n):
        shoe_size, price = map(int, input().split())
        customers.append((shoe_size, price))
    
    calc_earnings(shoes, customers)