collections.Counter()

Sort by

recency

|

1361 Discussions

|

  • + 0 comments
    from collections import Counter
    x = int(input())
    n = list(map(int,input().split()))
    m = int(input())
    sh =[]
    for i in range(m):
        sh.append(  list( map(int,input().split())) )
    
    dic = Counter(n)
    total =0
    
    for cust, price in sh:
        if dic[cust] > 0:  # Check if the requested size is available
            total += price
            dic[cust] -= 1  # Decrease the count for the size
            if dic[cust] == 0:  # If count becomes zero, remove the size
                del dic[cust]
    
    print(total)
    
  • + 0 comments

    nShoes = int(input()) nSizes = input().split() nSizes = list(map(lambda x: int(x), nSizes)) nCust = int(input()) totalEarnings = 0 for _ in range(nCust): preferSizePrice = input().split() preferSizePrice = list(map(lambda x: int(x), preferSizePrice)) if preferSizePrice[0] in nSizes: nSizes.remove(preferSizePrice[0]) totalEarnings += preferSizePrice[1] print(totalEarnings)

  • + 0 comments
    num_shoes = input()
    
    size_list = input().split()
    
    customers_count = int(input())
    
    sale_dict = dict()
    
    total = 0
    
    for item in range(customers_count):
        sale_dict.update({f'{item}' : (input().split())})
    
    for x,y in sale_dict.items():
        if y[0] in size_list:
            total += int(y[1])
            size_list.remove(y[0])
    
    print(total)
    
  • + 0 comments
    1. from collections import Counter
      1. X = int(input()) # number of shoes available
    2. Y = list(map(int,input().split())) # list of size of shoes
    3. counter = Counter(Y)
    4. N = int(input()) # number of customer
    5. sum_list = []
    6. for i in range(1,N+1):
    7. a,b = map(int,input().split())
    8. if(counter[a]!=0):
    9. sum_list.append(b)
    10. counter[a]-=1
    11. print(sum(sum_list))
  • + 0 comments

    from collections import Counter

    no_of_shoes = int(input()) shoe_size = map(int, input().split()) cus = int(input())

    earnings = 0

    shop = Counter(shoe_size)

    for i in range(cus): cus_shoe_size,price = map(int, input().split()) if shop[cus_shoe_size] > 0: shop[cus_shoe_size] -= 1 earnings += price print(earnings)