난이도: D3
package IM_study.swea1206;
import java.util.Scanner;
public class Solution {
static int[] map;
static int N;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for(int t=1;t<=10;t++) {
StringBuilder sb = new StringBuilder();
N = sc.nextInt();
map=new int[N];
for(int i=0;i<N;i++) {
map[i]=sc.nextInt();
}
int answer=0;
for(int i=2;i<N-2;i++) {
answer+=check(i);
}
sb.append("#"+t+" "+answer);
System.out.println(sb.toString());
}
}
public static int check(int current) {
int vh = 0;
if(map[current-2]>map[current]||map[current-1]>map[current]||map[current+1]>map[current]||map[current+2]>map[current]) {
return vh;
}else {
int a= Math.max(Math.max(map[current-2], map[current-1]),Math.max(map[current+2], map[current+1]));
vh=map[current]-a;
return vh;
}
}
}