공부, 기록

4050. 재관이의 대량 할인 D4 파이썬 본문

코딩

4050. 재관이의 대량 할인 D4 파이썬

무는빼주세요 2020. 8. 23. 13:09

문제링크 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIseXoKEUcDFAWN

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

T = int(input())
# 여러개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
for test_case in range(1, T + 1):
    # ///////////////////////////////////////////////////////////////////////////////////
    N= int(input())
    pricelist = list(map(int, input().split()))
    pricelist.sort()
    temp=0
    answer=0
    for i in range(len(pricelist)-1,-1,-1):
        temp+=1
        if temp ==3 :
            answer+=pricelist.pop()
            answer+=pricelist.pop()
            pricelist.pop()
            temp=0
    if temp ==2:
        answer+=pricelist.pop()
        answer+=pricelist.pop()
    elif temp == 1:
        answer+=pricelist.pop()
    print('#{} {}'.format(test_case, answer))
    # ///////////////////////////////////////////////////////////////////////////////////