[SWEA 1859 파이썬] 백만 장자 프로젝트

일단 해볼게·2023년 5월 20일
0

SWEA

목록 보기
1/1

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

T = int(input())

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

    result = 0
    max_num = 0

    for i in range(len(price) - 1, -1, -1): # 인덱스 때문에 len(price) - 1을 한다.

        if price[i] > max_num: # 최대값 갱신
            max_num = price[i]
        else:
            result += max_num - price[i]

    print(f"#{test_case} {result}")

테스트 케이스가 100만개이므로 시간복잡도를 주의해야한다.

profile
시도하고 More Do하는 백엔드 개발자입니다.

0개의 댓글