-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1206_View.java
39 lines (34 loc) · 956 Bytes
/
1206_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
30
31
32
33
34
35
36
37
38
39
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = 10;
for (int test_case = 1; test_case <= T; test_case++) {
int n = Integer.parseInt(br.readLine());
int b[] = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < n; i++) {
b[i] = Integer.parseInt(st.nextToken());
}
int answer = 0;
for (int i = 2; i < n - 2; i++) {
boolean check = true;
int view = 255;
for (int j = -2; j <= 2; j++) {
if (j == 0) continue;
if (b[i + j] > b[i]) {
check = false;
break;
}
view = Math.min(view, b[i] - b[i + j]);
}
if (check) {
answer += view;
}
}
System.out.println("#" + test_case + " " + answer);
}
}
}