python counter

Task

Raghu is a shoe shop owner. His shop has number of shoes. He has a list containing the size of each shoe he has in his shop. There are number of customers who are willing to pay amount of money only if they get the shoe of their desired size.

Your task is to compute how much money earned.

Input Format

The first line contains, the number of shoes. The second line contains the space separated list of all the shoe sizes in the shop. The third line contains, the number of customers. The next lines contain the space separated values of the desired by the customer and, the price of the shoe.

Sample Input

10
2 3 4 5 6 8 7 6 5 18
6
6 55
6 45
6 55
4 40
18 60
10 50
# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import Counter
X = int(raw_input().strip())
shoeSizeList = map(int,raw_input().strip().split(' '))
Cntr = Counter(shoeSizeList)

N = int(raw_input().strip())
#print 'list: ', shoeSizeList, type(shoeSizeList)

earnings = 0
for a0 in xrange(N):
    shoeSize,price = map(int, raw_input().strip().split(' '))
    if shoeSize in Cntr and Cntr[shoeSize] > 0:
        earnings += price
        Cntr[shoeSize] -= 1
        #print 'earnings: ', earnings

print earnings

Last updated

Was this helpful?