[프로그래머스] 2023 KAKAO BLIND RECRUITMENT | 이모티콘 할인행사
🔎문제
- 프로그래머스
- 2023 KAKAO BLIND RECRUITMENT
- Lv.2 이모티콘 할인행사
https://school.programmers.co.kr/learn/courses/30/lessons/150368?language=python3
💡풀이
python itertools의 product()
를 이용해 중복 순열을 구한 다음,
모든 결과를 리스트에 넣고 문제 조건대로 정렬했다.
중복 순열을 구하는 과정이 어렵다면 어려운 과정인데,, 파이썬이 이럴때는 정말 깡패다.
📃소스코드
from itertools import product
def solution(users, emoticons):
answer = []
n = len(users)
sale = [10, 20, 30, 40] # 할인율
cases = set()
cases = product(sale, repeat=len(emoticons))
for case in cases:
pay = [0 for _ in range(n)]
member = 0
for i in range(len(emoticons)):
for j in range(n):
if pay[j] == -1: # 이모티콘 플러스에 이미 가입
continue
if users[j][0] > case[i]: # 원하는 할인율에 미치지 못함
continue
pay[j] += emoticons[i] * (1 - case[i] * 0.01) # 할인 된 금액으로 구매
if pay[j] >= users[j][1]:
pay[j] = -1 # 이모티콘 플러스 가입
member += 1
tmp = 0
for p in pay:
if p != -1:
tmp += p
answer.append([member, tmp])
answer.sort(key=lambda x: (x[0], x[1]), reverse=True)
return [answer[0][0], int(answer[0][1])]