-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathcollection_counter.py
88 lines (70 loc) · 1.96 KB
/
collection_counter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Problem Statement
collections.Counter()
A counter is container, where elements are stored as dictionary keys and their counts are stored as dictionary values.
Sample Code
>>> from collections import Counter
>>>
>>> myList = [1,1,2,3,4,5,3,2,3,4,2,1,2,3]
>>> print Counter(myList)
Counter({2: 4, 3: 4, 1: 3, 4: 2, 5: 1})
>>>
>>> print Counter(myList).items()
[(1, 3), (2, 4), (3, 4), (4, 2), (5, 1)]
>>>
>>> print Counter(myList).keys()
[1, 2, 3, 4, 5]
>>>
>>> print Counter(myList).values()
[3, 4, 4, 2, 1]
Task
Raghu is a shoe shop owner. His shop has X number of shoes.
He has a list containing size of each shoe he has in his shop.
There are N number of customers, who are willing to pay xi amount of money only if they get the shoe of their desired size.
Your task is to compute, how much money Raghu earned.
Input Format
First line contains, X number of shoes.
Second line contains, space separated size of the shoes.
Third line contains, N number of customers.
Next N line contain, space separated values of shoe size and xi price of shoe.
Constraints
0<X<103
0<N≤103
20<xi<100
2<shoe size<20
Output Format
Print the amount of money earned by Raghu
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
Sample Output
200
Explanation
Customer 1 : Purchased shoe of size 6 for $ 55.
Customer 2 : Purchased shoe of size 6 for $ 45.
Customer 3 : Size 6 not available, so no purchase.
Customer 4 : Purchased shoe of size 4 for $ 40.
Customer 5 : Purchased shoe of size 18 for $ 60.
Customer 6 : Size 10 not available, so no purchase.
Total money earned = 55 + 45 + 40 + 60 = $ 200
"""
# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import Counter
X = int(input())
N = map(int,input().split())
x = int(input())
L = map(tuple,(map(int,input().split()) for _ in range(x)))
n = Counter(N)
p =0
for i in L:
if i[0] in n.keys() and n[i[0]] >0 :
n[i[0]] = n[i[0]]-1
p = p+i[1]
print(p)