HackerRank Python - collections.Counter()
collections.Counter()
A counter is a container that stores elements as dictionary keys, and their counts are stored as dictionary values.
- # Enter your code here. Read input from STDIN. Print output to STDOUT
-
- from collections import Counter
-
- num_shoes = int(input())
- shoe_sizes = Counter(map(int, input().split()))
- num_customers = int(input())
-
- cost = 0
- for _ in range(num_customers):
- size, price = map(int, input().split())
- if shoe_sizes[size]:
- cost += price
- shoe_sizes[size] -= 1
-
- print(cost)