Haribo ML, AI, MATH, Algorithm

이모티콘 할인행사

2023-11-23
Haribo

이모티콘 할인행사

코드

from itertools import product
import heapq

def solution(users, emoticons):
    discount_rates = [0.1, 0.2, 0.3, 0.4]
    discount_combinations = product(discount_rates, repeat=len(emoticons))
    results = []

    for discounts in discount_combinations:
        total_cost = 0
        num_membership = 0

        for hope_discount, payment in users:
            cost_for_user = sum(emoticon * (1 - discount) for emoticon, discount in zip(emoticons, discounts) if hope_discount <= discount * 100)
            if payment <= cost_for_user:
                num_membership += 1
            else:
                total_cost += cost_for_user

        heapq.heappush(results, (-num_membership, -total_cost))

    return [-x for x in heapq.heappop(results)]

Similar Posts

Comments