프로그래머스 150368. 이모티콘 할인행사

2024. 11. 24. 15:51·프로그래머스

https://school.programmers.co.kr/learn/courses/30/lessons/150368

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

def solution(users, emoticons):
    discounts = [10, 20, 30, 40]

    global max_sub, max_sale
    max_sub = 0  # 최대 서비스 가입자 수
    max_sale = 0  # 최대 이모티콘 판매액

    # 모든 이모티콘 할인 조합 생성
    def dfs(depth, combo):
        global max_sub, max_sale

        if depth == len(emoticons):  # 끝까지 채웠을 경우(이모티콘 길이만큼)
            sub_count = 0  # 서비스 가입자 수
            sales = 0  # 이모티콘 판매액

            for rate, limit in users:  # rate: 할인율, limit: 서비스가입기준
                total = 0  # user의 이모티콘 총 구매액

                for i, price in enumerate(emoticons):
                    if combo[i] >= rate:  # 할인율이 기준에 맞을 때만 구매
                        total += price * (100 - combo[i]) // 100

                if total >= limit:  # user의 이모티콘 총 구매액이 기준을 넘으면
                    sub_count += 1  # 서비스 가입
                else:
                    sales += total  # 이모티콘 판매액 추가

            # 현재 조합이 가장 나은지 확인
            if sub_count > max_sub or (sub_count == max_sub and sales > max_sale):
                max_sub = sub_count
                max_sale = sales
            return

        # 이모티콘마다 할인율을 선택하여 dfs 호출
        for discount in discounts:
            dfs(depth + 1, combo + [discount])

    dfs(0, [])

    return [max_sub, max_sale]
저작자표시 (새창열림)

'프로그래머스' 카테고리의 다른 글

프로그래머스 43105. 정수 삼각형  (0) 2024.12.21
프로그래머스 150369. 택배 배달과 수거하기  (0) 2024.11.26
프로그래머스 42839. 소수 찾기  (0) 2024.11.19
프로그래머스 42842. 카펫  (0) 2024.11.17
프로그래머스 42840. 모의고사  (0) 2024.11.16
'프로그래머스' 카테고리의 다른 글
  • 프로그래머스 43105. 정수 삼각형
  • 프로그래머스 150369. 택배 배달과 수거하기
  • 프로그래머스 42839. 소수 찾기
  • 프로그래머스 42842. 카펫
버그잡는고양이발
버그잡는고양이발
주니어 개발자입니다!
  • 버그잡는고양이발
    지극히평범한개발블로그
    버그잡는고양이발
  • 전체
    오늘
    어제
    • 분류 전체보기 (381)
      • React (16)
      • Next.js (5)
      • Javascript (5)
      • Typescript (4)
      • Node.js (2)
      • Cs (16)
      • 트러블 슈팅 (5)
      • Html (1)
      • Css (3)
      • Django (0)
      • vue (0)
      • Java (1)
      • Python (0)
      • 독서 (1)
      • 기타 (3)
      • 백준 (192)
      • swea (31)
      • 프로그래머스 (30)
      • 이코테 (4)
      • 99클럽 코테 스터디 (30)
      • ssafy (31)
      • IT기사 (1)
  • 블로그 메뉴

    • 홈
    • 태그
  • 인기 글

  • 태그

    코딩테스트준비
    99클럽
    개발자취업
    Til
    항해99
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
버그잡는고양이발
프로그래머스 150368. 이모티콘 할인행사
상단으로

티스토리툴바