SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=10;
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
int[] height = new int[N];
for(int i=0; i<N; i++){
height[i] = sc.nextInt();
}
int count = 0;
for(int j=2; j<N-2; j++){
int leftMax = Math.max(height[j-1], height[j-2]);
int rightMax = Math.max(height[j+1], height[j+2]);
if(height[j]>leftMax && height[j]>rightMax)
count+= height[j]-Math.max(leftMax, rightMax);
}
System.out.println("#" + test_case + " " + count);
}
}
}
만약 런타임 오류가 나거든
테스트 케이스 10개 고정인걸 확인하라
우테코 프리코스 4주차에서 내상을 크게 입었지만 일단 할 일은 하는중..
'SWEA' 카테고리의 다른 글
[SWEA] Sum (0) | 2024.11.16 |
---|---|
[SWEA] Flatten (1) | 2024.11.16 |
[SWEA] 등차수열 만들기 (1) | 2024.11.05 |
[SWEA] 식료품 가게 (0) | 2024.10.29 |
[SWEA] 회문의 회문 (0) | 2024.10.28 |