File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments