CodingTest/Content
백준 11508번 2+1 세일 풀이 및 정답(python)
코딩손
2025. 3. 24. 10:30
문제 설명 및 풀이
2개를 사면 1개를 공짜로 주기 때문에
가장 비싼 것부터 정렬하면 가장 이득을 볼 수 있습니다.
=> 내림차순으로 정렬
=> 3번째 아이템마다 가격계산 안하고 점프
정답 예시 코드
import sys
input = sys.stdin.readline
n = int(input())
price_list = [int(input()) for _ in range(n)]
price_list.sort(reverse=True)
total_price = 0
count = 0
for price in price_list:
count += 1
if count % 3 == 0:
count = 0
continue
total_price += price
print(total_price)