-
250409_프로그래머스 #150368. 이모티콘 할인행사알고리즘 2025. 4. 9. 17:11
문제
https://school.programmers.co.kr/learn/courses/30/lessons/150368
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
코드
from itertools import product def solution(users, emoticons): discounts = list(product([90, 80, 70, 60], repeat = len(emoticons))) # 할인율 p, b = 0, 0 for discount in discounts: prices = [] for i in range(len(emoticons)): prices.append((discount[i] * emoticons[i] // 100, 100 - discount[i])) plus, buy = 0, 0 for user in users: per, money = user current = 0 for price in prices: if price[1] >= per: current += price[0] if current >= money: plus += 1 else: buy += current if plus > p: p = plus b = buy elif plus == p and buy > b: b = buy return [p, b]
※ 데이터 개수가 적어서 빡구현으로 풀 수 있는 문제 ..! 나는 근데 2번 테스트케이스가 자꾸만 60원 차이나게 나와서 답답했는데, 알고보니 current > money가 아니라 current >= money 더라고 ^ 문제 잘 읽어야지 하하
product 활용법도 기억해두기 !
from itertools import product discounts = product([90, 80, 70, 60], repeat = len(emotiocons))
'알고리즘' 카테고리의 다른 글
250411_프로그래머스 #176962. 과제 진행하기 (0) 2025.04.11 250408_프로그래머스 #42890. 후보키 (0) 2025.04.08 250407_프로그래머스 #340212. [PCCP 기출문제] 2번 / 퍼즐 게임 챌린지 (0) 2025.04.07 250402_프로그래머스 #140107. 점 찍기 (2) 2025.04.02 250401_프로그래머스 #172927. 광물 캐기 (0) 2025.04.01