collections.Counter()

Sort by

recency

|

1406 Discussions

|

  • + 0 comments

    Way 1

    from collections import Counter
    
    X = int(input())
    shoe_sizes = Counter(map(int,input().split()))
    N = int(input())
    total_price = 0
    for i in range(N):
        size, price = list(map(int,input().split()))
        if shoe_sizes[size] !=0:
            total_price+= price
            shoe_sizes[size] -= 1
            
    print(total_price)
    

    Way 2

       X = int(input())
    shoe_sizes = list(map(int,input().split()))
    
    unique = set(shoe_sizes)
    count_dict = {size: 0 for size in unique}
    
    for shoe_size in shoe_sizes:
        count_dict[shoe_size] +=1
    
    N = int(input())
    total_price = 0
    for i in range(N):
        size, price = list(map(int,input().split()))
        if size in count_dict.keys():
            if count_dict[size] !=0:
                total_price+= price
                count_dict[size] -= 1
            
    print(total_price)    
    
  • + 0 comments

    from collections import Counter

    X = int(input()) sizes = list(map(int, input().split())) customers = int(input()) orders = list()

    for i in range(customers): x, y = map(int, input().split()) orders.append({x: y})

    sizes_count = Counter(sizes)

    list_prices = list()

    for order in orders: k, v = list(order.items())[0] if (k in sizes_count.keys()) & (sizes_count[k] > 0): sizes_count[k] -= 1 list_prices.append(v)

    print(sum(list_prices))

  • + 0 comments

    here in constraints 2

  • + 0 comments
    from collections import Counter
    
    x = input()
    
    shoeList = list(input().split())
    
    shoeListOrg = Counter(shoeList)
    
    N = int(input())
    
    price = list()
    
    for i in range(N):
        sizeAndPrice = list(input().split())
        
        for key in shoeListOrg:
            
            if key == sizeAndPrice[0]:
                if shoeListOrg[key] != 0:
                    price.append(int(sizeAndPrice[1]))
                    shoeListOrg[key] = shoeListOrg[key] - 1
            else:
                pass
    
    print(sum(price))
        
    
  • + 0 comments

    Here's my solution to this problem:-

    from collections import Counter shoes=int(input()) shoe_size=list(map(int,input().split())) counter=Counter(shoe_size) customers=int(input()) lst=[] for i in range(1,customers+1): customer_info,price=map(int,input().split()) if counter[customer_info]>0: counter[customer_info]-=1 lst.append(price) else: pass print(sum(lst))