We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
collections.Counter()
collections.Counter()
Sort by
recency
|
1406 Discussions
|
Please Login in order to post a comment
Way 1
Way 2
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))
here in constraints 2
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))