본문 바로가기

Algorithms/SW Expert Academy

[Java] SW Expert Academy 1859번 문제: 백만 장자 프로젝트(Brute Force)

728x90

--- 문제 ---

  • 1859 번 : 백만 장자 프로젝트

--- 코드 ---

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Sw1859 {

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		System.setIn(new FileInputStream("./src/1859.txt"));

		Scanner sc = new Scanner(System.in);
		
		int T=sc.nextInt();
		
		for(int test_case = 1; test_case <= T; test_case++) {
			
			int n = sc.nextInt();
			int[] pay = new int[n];
			for(int i=0; i<n; ++i) {
				pay[i] = sc.nextInt();
			}
			long sum = 0;
			int max = 0;
			
			for(int i=n-1; i>=0; --i) {
				if(max<pay[i]) {
					max = pay[i];
				}
				else {
					int mg = max - pay[i];
					sum+=mg;
				}
			}
			System.out.printf("#%d %d%n",test_case,sum);
		}
	}

}

 

--- 출처 ---

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

 

SW Expert Academy

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

swexpertacademy.com

 

반응형