-
[SWEA] [JAVA] [Difficulty 2] [1859] 백만 장자 프로젝트SW Expert Academy 2022. 11. 18. 23:56
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int T= Integer.parseInt(br.readLine()); // 테스트케이스 for(int tc=1; tc<=T; tc++) { int N = Integer.parseInt(br.readLine()); int arr[] = new int[N]; StringTokenizer st = new StringTokenizer(br.readLine()," "); for(int i=0; i<N; i++) { int num = Integer.parseInt(st.nextToken()); // 점수 arr[i] = num; } long profit = 0; int max = 0; // 뒤에서부터 체크 for(int i=N-1; i>=0; i--) { int today = arr[i]; if(max > today) { profit += max - today; } // 최대값 갱신 else { max = today; } } sb.append("#" + tc + " " + profit + "\n"); } System.out.println(sb); } }
참조 - 동영상 시청하시면 이해 잘돼용
[SWEA] 1859. 백만장자 프로젝트
SWEA D2 1859 백만장자 프로젝트 문제링크 SW Expert Academy * 일단 문제를 정독 하고 1시간 이상 반드시 고민이 필요합니다. 동영상 설명 1시간 이상 고민 했지만 아이디어가 떠오르지 않는다면 동영상
goodteacher.tistory.com
'SW Expert Academy' 카테고리의 다른 글
[SWEA] [JAVA] [Difficulty 3] [13218] 조별과제 (0) 2022.11.20 [SWEA] [JAVA] [Difficulty 3] [12368] 24시간 (0) 2022.11.20 [SWEA] [JAVA] [Difficulty 2] [1984] 중간 평균값 구하기 (0) 2022.11.18 [SWEA] [JAVA] [Difficulty 2] [1204] [S/W 문제해결 기본] 1일차 - 최빈수 구하기 (0) 2022.11.18 [SWEA] [JAVA] [Difficulty 2] [1946] 간단한 압축 풀기 (0) 2022.11.18