문제: https://www.swexpertacademy.com/main/code/problem/problemDetail.do
import sys
read = lambda : sys.stdin.readline().strip()
for t in range(10):
n = int(read())
l = list(map(int, read().split()))
ans = 0
for i in range(0, len(l)-4):
tmp = [l[i], l[i+1], l[i+2], l[i+3], l[i+4]]
if max(tmp) != tmp[2] : continue
else:
stnd = tmp[2]
tmp.pop(2)
ans += (stnd - max(tmp))st
print("#",t+1,ans)
import java.util.*;
public class Solution {
private static final Scanner sc = new Scanner(System.in);
public static void main(String args[]) {
for(int t=1; t <= 10; t++){
int n = sc.nextInt();
int[] l = new int[n+1];
for (int i=0; i<n; i++) {
l[i] = sc.nextInt();
}
int ans = 0;
int[] tmp = new int[6];
for(int i =0; i< l.length-5; i++){
int maxL = 0;
for(int j =0; j < 5; j++){
tmp[j] = l[i+j];
if( maxL < l[i+j] ){
maxL = l[i+j];
}
}
if( maxL == tmp[2] ){
int stnd = tmp[2];
tmp[2] = 0;
maxL = 0;
for(int j =0; j < 5; j++){
if( maxL < tmp[j] ){
maxL = tmp[j];
}
}
int tmp_max = stnd - maxL;
ans += tmp_max;
}
}
System.out.println("#"+t +" "+ans);
}
}
}
package project;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void countViewRight(int[] building){
int viewRight = 0;
for(int i = 2 ; i<building.length-2; i++){
int boundaryTallBuilding = Math.max( Math.max(building[i-2],building[i-1]), Math.max(building[i+1],building[i+2]) );
int difference = building[i] - boundaryTallBuilding;
if( difference > 0){
viewRight += difference;
}
}
System.out.println("viewRight"+viewRight);
}
public static void solved(){
// int buildingCount = sc.nextInt();
int buildingCount = 9;
int[] building = new int[buildingCount];
for(int i =0; i < building.length; i++){
if( (i == 0) || (i == 1) || (i == buildingCount-2) || (i == buildingCount-1)){
building[i] = 0;
} else{
building[i] = sc.nextInt();
}
}
countViewRight(building);
}
public static void main(String args[]) {
// int testCase = sc.nextInt();
int testCase = 1;
for(int i=0; i<testCase;i++){
solved();
}
}
}