Skip to content

Commit b9099af

Browse files
authored
[20251115] BOJ / G1 / 난민 / 이강현
1 parent 115cac1 commit b9099af

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lkhyun/202511/15 BOJ G1 난민.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringBuilder sb = new StringBuilder();
9+
static StringTokenizer st;
10+
static int N;
11+
12+
static PriorityQueue<Long> minheap = new PriorityQueue<>();
13+
static PriorityQueue<Long> maxheap = new PriorityQueue<>(Comparator.reverseOrder());
14+
public static void main(String[] args) throws Exception {
15+
N = Integer.parseInt(br.readLine());
16+
long prevY = 0;
17+
long accumulation = 0; //누적 이동거리
18+
for(int i = 1; i <= N; i++){
19+
st = new StringTokenizer(br.readLine());
20+
long curX = Long.parseLong(st.nextToken());
21+
long curY = Long.parseLong(st.nextToken());
22+
23+
maxheap.add(curY); //일단 maxheap에 넣음.
24+
minheap.add(maxheap.poll());
25+
if(maxheap.size() < minheap.size()){
26+
maxheap.add(minheap.poll());
27+
}
28+
if(i % 2 == 0){
29+
accumulation += (Math.abs(curX) + Math.abs(prevY - curY));
30+
prevY = maxheap.peek();
31+
}else{
32+
prevY = maxheap.peek();
33+
accumulation += (Math.abs(curX) + Math.abs(prevY - curY));
34+
}
35+
bw.write(prevY + " " + accumulation + "\n");
36+
}
37+
bw.close();
38+
}
39+
}
40+
```

0 commit comments

Comments
 (0)