SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
📌 작성한 코드
from itertools import combinations
T = int(input())
for tc in range(1,1+T):
arr = list(map(int,input().split()))
combi = list(map(list,combinations(arr,3)))
total = []
for c in combi:
total.append(sum(c))
total = sorted(list(set(total)), reverse=True)
print(f'#{tc} {total[4]}')
📌 풀이
- combination 사용해서 3개 고르기 -> 더한 값 배열에 저장
- 배열에서 중복을 제거하기 위해 set에 넣었다가 다시 배열로 만들기 -> 내림차순으로 정렬하기
- 5번째 항목 출력하기

'알고리즘 > SWEA' 카테고리의 다른 글
| [Python] SWEA D3 : 4047 - 영준이의 카드 카운팅 (0) | 2023.11.16 |
|---|---|
| [Python] SWEA D3 : 8016 - 홀수 피라미드 (0) | 2023.11.16 |
| [Python] SWEA D3 : 3431 - 준환이의 운동관리 (0) | 2023.11.16 |
| [Python] SWEA D3 : 3499 - 퍼펙트 셔플 (0) | 2023.11.16 |
| [Python] SWEA D3 : 3750 - Digit sum (2) | 2023.11.14 |