[JAVA] SWEA 6730 - 장애물 경주 난이도

hyng·2022년 2월 19일
0

SWEA

목록 보기
37/78

import java.util.*;
class Solution
{
	public static void main(String args[]) throws Exception
	{
        Scanner sc = new Scanner(System.in);
        StringBuffer sb = new StringBuffer();

        int T = sc.nextInt();
        for(int tc=1; tc<=T; tc++){
            sb.append("#").append(tc).append(" ");

            ArrayList<Integer> block = new ArrayList<>();
            int N = sc.nextInt();
            for(int i=0; i<N; i++){
                block.add(sc.nextInt());
            }

            int upLevel = 0, downLevel = 0;
            for(int i=1; i<N; i++){
                int cur = block.get(i-1);
                int nxt = block.get(i);

                if(nxt > cur){
                    //올라가기
                    upLevel = Math.max(upLevel, nxt - cur);
                }else{
                    //내려가기
                    downLevel = Math.max(downLevel, cur - nxt);
                }
            }
            sb.append(upLevel).append(" ").append(downLevel).append("\n");



        }
        System.out.println(sb);

    }

}
profile
공부하고 알게 된 내용을 기록하는 블로그

0개의 댓글