슈콩

[SWEA] 장애물 경주 난이도 본문

Algorithms/SWEA

[SWEA] 장애물 경주 난이도

shukong 2025. 11. 17. 15:47

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWefy5x65PoDFAUh

 

SW Expert Academy

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

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			int n = Integer.parseInt(br.readLine());
			int[] h = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				h[i] = Integer.parseInt(st.nextToken());
			}
			int down = 0;
			int up = 0;
			for(int i=0;i<n-1;i++) {
				if(h[i]<h[i+1]) up = Math.max(up, h[i+1]-h[i]);
				if(h[i]>h[i+1]) down = Math.max(down, h[i]-h[i+1]);
			}
			System.out.println("#"+tc+" "+up+" "+down);
		}
	}
}

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

[SWEA] 두문자어  (0) 2025.11.17
[SWEA] 시험  (0) 2025.11.17
[SWEA] 문제 제목 붙이기  (0) 2025.11.17
[SWEA] 준홍이의 카드놀이  (0) 2025.11.17
[SWEA] 모음이 보이지 않는 사람  (0) 2025.11.17