PS/Baekjoon Online Judge

[백준 15083] Life Savings [Python]

kimyoungrok 2024. 7. 25. 23:41
728x90

문제

Stanley is very prudent when it comes to his finances. He enjoys a somewhat spartan lifestyle and watches every penny he spends. Those few who call him friend view him as economical, abstemious, and parsimonious. He’s basically a miserly tightwad.

Stan will never go shopping unless he has coupons. At the moment he has a bit of a conundrum. There are three items he wants to buy which have list costs of 100,50 and $40. He has one coupon for 20% off his entire purchase which can’t be used with any other coupon, and two coupons — one for 30% off any one item and one for 25% off any one item — which can be used together. He’s not sure if using the first coupon by itself will save him more money than using the other two coupons together or vice versa, and the people standing in line behind him at the checkout counter are getting a little impatient. Can you help Stan with his problem and make cents out of this situation?

입력

Input consists of two lines. The first line starts with three positive integers p1 p2 p3 (p1, p2, p3 ≤ 1000) which are the prices of three objects to be purchased. The second line contains three positive integers c1 c2 c3 (c1, c2, c3 ≤ 100) where c1 is the coupon percentage for the entire purchase (and cannot be used with any other coupon) and c2 and c3 are two one-item coupons (which can be used together but on separate items).

출력

If using the single entire-purchase coupon saves Stan more money, display the word one followed by the amount of savings; otherwise display the word two following by the best savings using the two one-item coupons. All savings should be output with two digits after the decimal point.


풀이

 물품의 가격 p1, p2, p3에 대해 전체 할인 쿠폰 c1을 적용한 할인 금액을 구하고,

별도로 중복 적용 가능한 쿠폰인 c2, c3를 가장 비싼 P에 대해 최대 할인율을 적용한 금액을 구해주자.

우선 물품의 가격 P를 DESC 정렬해주자.

 C[1], C[2] 또한 DESC순으로 배치해주어 최대 할인율이 적용한 금액을 구하면 된다.

두 할인 금액을 비교해 할인금액이 큰 방법과 금액을 출력하면 된다.


소스코드

보기


출처

https://www.acmicpc.net/problem/15083

728x90