-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ2666Fail.java
More file actions
47 lines (35 loc) · 1.07 KB
/
BOJ2666Fail.java
File metadata and controls
47 lines (35 loc) · 1.07 KB
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
43
44
45
46
47
package quki.algorithm.dp;
import java.util.Scanner;
public class BOJ2666Fail {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int A = sc.nextInt();
int B = sc.nextInt();
int k = sc.nextInt(); //이동해야하는 벽장문 개수
int a[] = new int[k];
int d[] = new int[k]; // 이전 벽장문과의 간격 차이 중 최솟값 저장
for (int i = 0; i < k; i++) {
a[i] = sc.nextInt();
}
for (int i = 0; i < k; i++) {
int t1 = Math.abs(a[i]-A);
int t2 = Math.abs(a[i]-B);
if(t1>t2){
int temp1 = t1;
t1 = t2;
t2 = temp1;
int temp2 = A;
A = B;
B = temp2;
}
d[i] = t1;
A = a[i];
}
int ans = 0;
for(int i = 0; i<d.length;i++){
ans+=d[i];
}
System.out.println(ans);
}
}