슈콩

[BOJ] 백준 11501 주식 본문

Algorithms/Baekjoon

[BOJ] 백준 11501 주식

shukong 2025. 8. 27. 22:24

[문제]

https://www.acmicpc.net/problem/11501

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st;
    	int T = Integer.parseInt(br.readLine());
    	while(T-->0) {
    		int n = Integer.parseInt(br.readLine());
    		int[] stock = new int[n];
    		st = new StringTokenizer(br.readLine());
    		for(int i=0;i<n;i++) {
    			stock[i] = Integer.parseInt(st.nextToken());
    		}
    		long result = 0;
    		int max = stock[n-1];
    		for(int i=n-2;i>=0;i--) {
    			if(max<stock[i]) max = stock[i];
    			result += max - stock[i];
    		}
    		System.out.println(result);
    	}
    }
}

'Algorithms > Baekjoon' 카테고리의 다른 글

[BOJ] 백준 1541 잃어버린 괄호  (0) 2025.08.27
[BOJ] 백준 1439 뒤집기  (0) 2025.08.27
[BOJ] 백준 11399 ATM  (0) 2025.08.27
[BOJ] 백준 12865 평범한 배낭  (0) 2025.08.27
[BOJ] 백준 1026 보물  (0) 2025.08.27