SWEA_1206) View
SWEA
# D3
1206) View (19.10.21)
문제 링크 (SW Expert Academy)
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
40
41
42
|
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer tk;
for(int test=1; test<=10; test++) {
int n = Integer.parseInt(br.readLine());
int[] ap = new int[n];
tk = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) {
ap[i] = Integer.parseInt(tk.nextToken());
}
int[][] map = new int[3][n];
for(int i=2;i<n-2;i++) {
if(ap[i-1]<ap[i] && ap[i-2]<ap[i]) {
map[0][i] = Math.min(ap[i]-ap[i-1], ap[i]-ap[i-2]);
}
if(ap[i]>ap[i+1] && ap[i]>ap[i+2]) {
map[1][i] = Math.min(ap[i]-ap[i+1], ap[i]-ap[i+2]);
}
if(map[0][i]>0 && map[1][i]>0) map[2][i] = Math.min(map[0][i], map[1][i]);
}
int min = 0;
for(int i:map[2]) {
min = min+i;
}
bw.write("#" + test + " " + min + "\n");
}
bw.flush();
bw.close();
}
}
| cs |
댓글
댓글 쓰기