-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.java
29 lines (25 loc) · 868 Bytes
/
View.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package swexport.d3;
import java.util.Scanner;
// SW Expert Academy 1206번 View 문제
public class View {
public static int solution(int [] arr){
int n = arr.length, answer = 0;
for (int i = 2; i < n - 2; i++){
int temp = arr[i];
int min = Math.min(Math.min(Math.min(temp - arr[i - 1], temp - arr[i - 2]), temp - arr[i + 1]), temp - arr[i + 2]);
min = min < 0 ? 0 : min;
answer += min;
}
return answer;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
int n = sc.nextInt();
int [] arr = new int[n];
for (int j = 0; j < n; j++) arr[j] = sc.nextInt();
System.out.printf("%s %d\n","#"+ (i+1) ,solution(arr));
}
sc.close();
}
}