File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ input : 총 유제품 수 N , 각 제품 가격
3+ goal : 모두 살때 최소 비용
4+ Condition
5+ 1. 3개 중 가장 싼것만 무료, 나머지 2개는 가격 지불
6+
7+ # Flow(greedy)
8+ 1. 3개씩 묶기
9+ - 값이 큰 놈들 순으로 정렬
10+ 2. 각 묶음 별 제출 가격 count 하기
11+
12+ 문제 : https://www.acmicpc.net/problem/11508
13+ """
14+
15+ import sys
16+ input = sys .stdin .readline
17+ n = int (input ())
18+ products = list ()
19+ # 1. price 입력 받기
20+ for i in range (n ):
21+ each_price = int (input ())
22+ products .append (each_price )
23+
24+ # 2. 가격 비싼 순 = priority으로 item 정렬
25+ products = sorted (products , reverse = True )
26+ print (products )
27+ # 2. for 문으로 총 price 계산하기
28+ # 이때 item 3개 묶음이 충족 되면, 3개중 최소 가격을 전체 price 에서 빼기
29+ bags = list ()
30+ total = 0
31+ for item in products :
32+ if len (bags ) < 3 :
33+ bags .append (item )
34+ total += item
35+ # print(bags)
36+ if len (bags ) == 3 :
37+ free = min (bags )
38+ total -= free
39+ bags = []
40+ print (total )
You can’t perform that action at this time.
0 commit comments