SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
[코드]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
for (int test_case = 1; test_case <= 10; test_case++) {
int N = sc.nextInt();
int[] array = new int[N];
for (int i = 0; i < N; i++) {
array[i] = sc.nextInt();
}
int count = 0; // 조망권 확보된 세대 수
for (int i = 2; i < N - 2; i++) {
int max = Math.max(array[i - 2], Math.max(array[i - 1], Math.max(array[i + 1], array[i + 2]))); // 2칸 이내
// 최대값
if (array[i] - max > 0) {
count += array[i] - max;
}
}
System.out.println("#" + test_case + " " + count);
}
}
}'Study > Test(Java)' 카테고리의 다른 글
| [SWEA] 1289 원재의 메모리 복구하기 Java (0) | 2024.05.14 |
|---|---|
| [SWEA] 1208 [S/W 문제해결 기본] 1일차 - Flatten Java (0) | 2024.05.14 |
| [SWEA] 1983 조교의 성적 매기기 Java (0) | 2024.05.13 |
| [SWEA] 2001 파리 퇴치 Java (0) | 2024.05.12 |
| [백준] 1966 프린터 큐 Java (0) | 2024.04.29 |