-
Notifications
You must be signed in to change notification settings - Fork 6
/
JIHANEOL.java
44 lines (40 loc) · 1.47 KB
/
JIHANEOL.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
40
41
42
43
44
// 구글에 도움으로 풀었다 .....
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;
public class JIHANEOL {
// 이해가 안간다.
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] target = new int[N];
int prev = 0;
int answer = 0;
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
target[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
target[i] = Integer.parseInt(st.nextToken())-target[i];
}
System.out.println(Arrays.toString(target));
if(N>1) {
prev = target[0];
for (int i = 1; i < N; i++) {
if(prev*target[i]<0){ // 다르면
answer += Math.abs(prev); // 수학을 잘해야 하나...........
}else if(Math.abs(prev)>=Math.abs(target[i])){
answer += Math.abs(prev)-Math.abs(target[i]);
}
prev = target[i];
System.out.println(prev+" "+ answer);
}
}else{
answer = target[0];
}
answer += Math.abs(prev);
System.out.println(answer);
}
}