11508 - 2+1 세일

LeeKyoungChang·2022년 6월 7일
0

Algorithm

목록 보기
148/203
post-thumbnail

📚 11508 - 2+1 세일

2+1 세일

 

이해

내림차순으로 정렬한 후, 배열을 3의 배수 크기로 만든 후, 반복문을 통해 계산하면 된다.

 

소스

import sys  
  
read = sys.stdin.readline  
  
n = int(read())  
  
product = []  
  
for i in range(n):  
    product.append(int(read()))  
  
product.sort(reverse=True)  
  
if len(product) % 3 != 0:  
    product = product + [0] * (len(product) % 3)  
  
answer = 0  
  
for i in range(0, n, 3):  
    answer += product[i] + product[i + 1]  
  
print(answer)

 

profile
"야, (오류 만났어?) 너두 (해결) 할 수 있어"

0개의 댓글