알고리즘/프로그래머스
[2023 KAKAO BLIND RECRUITMENT] 이모티콘 할인 행사 - Python
Dev. Dong
2025. 1. 11. 15:17
문제링크 - https://school.programmers.co.kr/learn/courses/30/lessons/150368
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[문제 간단 요약]
1. 가입자 수와 매출액을 최대로 하는 값을 구하는 구현 문제
2. 가입자 수를 우선 조건으로 하고 매출액을 다음 조건으로 값을 구해야함
[문제 해결 방안]
1. 할인에 해당하는 배열 조합을 이모티콘의 수만큼 만들기
2. 이모티콘이 할인 가능한 모든 금액을 구하고 조건에 맞는 가입자 수와 매출액을 하여 문제 해결
[문제 해결 코드 - Python]
from itertools import product
def solution(users, emoticons):
discount_rates = [10, 20, 30, 40]
max_result = [0, 0]
for discount_rate in product(discount_rates, repeat=len(emoticons)):
pub = 0
profit = 0
for user in users:
rate = user[0]
max_price = user[1]
discount_price = 0
for discount, emoticon in zip(discount_rate, emoticons):
if rate <= discount:
discount_price += emoticon * (100-discount) //100
if discount_price >= max_price:
pub += 1
else:
profit += discount_price
if max_result[0] < pub:
max_result[0] = pub
max_result[1] = profit
elif max_result[0] == pub:
max_result[1] = max(max_result[1], profit)
return max_result