collections.Counter()

Sort by

recency

|

1391 Discussions

|

  • + 0 comments
    # My solution creates a list of customers as sublists [size, price]. It then iterates through this list, checks the inventory for that shoe size, adds the price to the earnings and decreases the inventory by one.
    
    from collections import Counter
    
    num_shoes = int(input())
    inventory = Counter(list(map(int, list(input().split()))))
    num_customers = int(input())
    customers = []
    for i in range(num_customers):
        customers.append(list(map(int, list(input().split()))))
    
    earned = 0
    for customer in customers:
        if inventory[customer[0]] > 0:
            earned += customer[1]
        inventory[customer[0]] -= 1
    print(earned)
    
  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from collections import Counter
    X = int(input())
    shoe_sizes = list(map(int,input().split()))
    N = int(input())
    total_earned = 0
    for i in range(N):
        size,price = map(int,input().split())
        if size in shoe_sizes:
            total_earned += price
            shoe_sizes.remove(size)
    
    print(total_earned)
        
    
  • + 0 comments
    from collections import Counter
    n=int(input());tot=0
    size=Counter(map(int,input().split()))
    sell=int(input())
    for _ in range(sell):
        shoeS,price=map(int,input().split())
        if shoeS in size and size[shoeS] >0:
            tot+=price
            size.subtract({shoeS:1})
        else:
            continue
    print(tot)
    
  • + 0 comments

    // writtten by my freind from collections import Counter n = int(input()) ls = list(map(int,input().split())) test = int(input()) ls = Counter(ls) tot=0 for i in range(test): n,m = map(int,input().split()) if(ls[n] > 0): tot+=m

    ls[n]-=1
    

    print(tot)

  • + 0 comments

    from collections import Counter

    def calculate_earnings(shoe_sizes, customers): stock = Counter(shoe_sizes) earnings = 0

    for size, price in customers:
        if stock[size]:
            earnings += price
            stock[size] -= 1
    
    return earnings
    

    if name == 'main': x = int(input()) shoe_sizes = list(map(int, input().split())) n = int(input()) customers = [tuple(map(int, input().split())) for _ in range(n)]

    total_earnings = calculate_earnings(shoe_sizes, customers)
    print(total_earnings)