Maximum Ice Cream Bars

Solution
class Solution:
    def maxIceCream(self, costs: List[int], coins: int) -> int:
        m = max(costs)
        freq = [0] * (m + 1)
        for cost in costs:
            freq[cost] += 1
        
        ice_creams = 0
        for cost in range(1, m + 1):
            if not freq[cost]: continue
            if coins < cost: break
            
            count = min(freq[cost], coins // cost)
            coins -= cost * count
            ice_creams += count
            
        return ice_creams