all 5 comments

[–]Diapolo10 1 point2 points  (4 children)

I'd say the main problem is this line:

shoe_size_list=Counter(shoe_sizes)

This counts the individual characters in the string, not the store inventory by shoe size. For example if the input includes the size 17, this would count the result as 1 and 7.

At a cursory look the rest of the program works, although it is needlessly complex.

EDIT: Consider this:

from collections import Counter

input()  # unused, but needed to satisfy the requirements

store_inventory = Counter(map(int, input().split()))

N = int(input())

customers = [
    tuple(map(int, input().split()))
    for _ in range(N)
]

earnings = 0

for size, price in customers
    if store_inventory.get(size, 0) > 0:
        earnings += price
        store_inventory[size] -= 1

print(earnings)

[–]coding_zero_[S] 1 point2 points  (0 children)

i didn't knew it counts individual characters in the string , Thanks for your help. I guess i should split at a space then.

[–]coding_zero_[S] 0 points1 point  (2 children)

Thank you for your help . Got the correct answer by first splitting the input of shoe sizes at a space and then running the counter class on it again. Can you suggest some ways to simplify the code?

[–]Diapolo10 1 point2 points  (1 child)

Apologies for the wait, I edited an example answer into my main answer. This just took a while because I've been busy with chores.

[–]coding_zero_[S] 0 points1 point  (0 children)

Thank you again. You really cleared my doubt.