1859 - 백만장자 프로젝트
문제 설명
문제 풀이
규칙성을 찾는다.
- 전체 배열 요소 중 가장 큰 값이 매매 금액이 될 때까지 구매한 후 당일에 판다.
- 팔고 그다음 index부터 max 값을 찾고 1번 과정을 반복한다.
코드
T = int(input())
for tc in range(1, T+1):
    N = int(input())
    arr = list(map(int, input().split()))
    result = s = maxI = 0
    while s < N:
        maxI = s
        for i in range(s, N):
            if arr[maxI] < arr[i]:
                maxI = i
        for i in range(s, maxI):
            result += arr[maxI] - arr[i]
        s = maxI + 1
    print(f'#{tc} {result}')
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Author And Source
                            
                            이 문제에 관하여(1859 - 백만장자 프로젝트), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://velog.io/@singco/1859-백만장자-프로젝트
                            
                            
                            
                                저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
T = int(input())
for tc in range(1, T+1):
    N = int(input())
    arr = list(map(int, input().split()))
    result = s = maxI = 0
    while s < N:
        maxI = s
        for i in range(s, N):
            if arr[maxI] < arr[i]:
                maxI = i
        for i in range(s, maxI):
            result += arr[maxI] - arr[i]
        s = maxI + 1
    print(f'#{tc} {result}')Author And Source
이 문제에 관하여(1859 - 백만장자 프로젝트), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@singco/1859-백만장자-프로젝트저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)