SWEA

[SWEA] 1859. 백만 장자 프로젝트(Python)

가은(JANE) 2024. 11. 16. 20:06

#Problem

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5LrsUaDxcDFAXc&categoryId=AV5LrsUaDxcDFAXc&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1

 

SW Expert Academy

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

swexpertacademy.com

 

#Think

  • 사실 D2 문제 중에 제일 위에 뜨기 전에 처음으로 도전했던 문제인데 포기했었음ㅋ
  • 뒤에서부터 출력해서 가장 큰 수라고 지정하고, 큰 수부터 지정하면 빼서 이득에 더해준다.

#Code

T=int(input())

for tc in range(1,T+1):
    day=int(input())
    price = list(map(int,input().split()))

    benefit=0
    maxprice=0
    
    for p in reversed(price):
        if p > maxprice :
            maxprice = p
        else:
            benefit += maxprice - p
        
    print(f"#{tc} {benefit}")