less than 1 minute read

1. 개요

2. 풀이

from itertools import product

def solution(users, emoticons):
    # 이모티콘의 할인율은 10, 20, 30, 40, 4개중 하나이다.
    # 중복순열을 통해 모든경우의 수를 뽑아낸다.
    # 최대 4^11 = 2^22 = 2048*2048 의 경우의 수가 있다.
    cases = product([10, 20, 30, 40], repeat = len(emoticons))
    finalEnrolled = finalSelled = 0
    
    for case in cases:
        emotionInfos = [[r, e] for r, e in zip(case, emoticons)]
        enrolled = selled = 0
        
        # 모든 유저들을 돌려보며 이모티콘 판매수익을 계산한다.
        for userRate, cost in users:
            userSelled = 0
            
            for eRate, emoticon in emotionInfos:
                if eRate >= userRate:
                    userSelled += (emoticon//100)*(100-eRate)
                    
            if userSelled >= cost:
                enrolled += 1
            else:
                selled += userSelled

        # 이모티콘 수익이 선을 넘으면 멤버십을 등록 회원수를 증가시킨다.
        # 아니면 판매 수익을 추가해주면 된다.
        if finalEnrolled < enrolled:
            finalEnrolled, finalSelled = enrolled, selled
        elif finalEnrolled == enrolled and finalSelled < selled:
            finalEnrolled, finalSelled = enrolled, selled

    return [finalEnrolled, finalSelled]

Leave a comment