문제
장바구니에 담긴 가격을 모두 더하세요. 합계가 discount_threshold 이상이면 전체 합계에서 discount_percent퍼센트를 할인합니다.
cart_total(prices, discount_threshold, discount_percent)를 구현하세요.
입력
prices: 상품 가격들. discount_threshold: 할인이 적용되는 합계 기준. discount_percent: 할인율(퍼센트).
출력
지불할 금액을 반환합니다.
제약 조건
0 ≤ 길이 ≤ 1,000; 0 ≤ 각 가격 ≤ 100,000; 0 ≤ discount_percent ≤ 100
예시
예시 1
입력:
prices = [40, 35, 25]
discount_threshold = 100
discount_percent = 10
예상 출력:
expected = 90.0
입력:
std::vector<long long> prices = {40, 35, 25};
long long discount_threshold = 100;
long long discount_percent = 10;
예상 출력:
double expected = 90.0;
입력:
long[] prices = new long[] {40, 35, 25};
long discount_threshold = 100;
long discount_percent = 10;
예상 출력:
double expected = 90.0;
설명
합계 100이 기준에 도달하므로 10% 할인되어 90입니다.
예시 2
입력:
prices = [20, 30]
discount_threshold = 100
discount_percent = 10
예상 출력:
expected = 50.0
입력:
std::vector<long long> prices = {20, 30};
long long discount_threshold = 100;
long long discount_percent = 10;
예상 출력:
double expected = 50.0;
입력:
long[] prices = new long[] {20, 30};
long discount_threshold = 100;
long discount_percent = 10;
예상 출력:
double expected = 50.0;
설명
합계 50은 100보다 작으므로 할인 없이 50입니다.
접근 방법
먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.
힌트 1
먼저 할인 전 장바구니 총액을 구하세요.
힌트 2
총액이 기준에 도달할 때만 퍼센트 할인을 적용합니다.
힌트 3
할인은 각 상품별이 아니라 전체 주문 금액에서 적용해야 합니다.
예상 복잡도
시간 O(n), 추가 공간 O(1)
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.