From b9099af599963ed6798cc37083efb26ae5dcddb1 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sat, 15 Nov 2025 17:32:38 +0900 Subject: [PATCH] =?UTF-8?q?[20251115]=20BOJ=20/=20G1=20/=20=EB=82=9C?= =?UTF-8?q?=EB=AF=BC=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../15 BOJ G1 \353\202\234\353\257\274.md" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "lkhyun/202511/15 BOJ G1 \353\202\234\353\257\274.md" diff --git "a/lkhyun/202511/15 BOJ G1 \353\202\234\353\257\274.md" "b/lkhyun/202511/15 BOJ G1 \353\202\234\353\257\274.md" new file mode 100644 index 00000000..97f4f258 --- /dev/null +++ "b/lkhyun/202511/15 BOJ G1 \353\202\234\353\257\274.md" @@ -0,0 +1,40 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringBuilder sb = new StringBuilder(); + static StringTokenizer st; + static int N; + + static PriorityQueue minheap = new PriorityQueue<>(); + static PriorityQueue maxheap = new PriorityQueue<>(Comparator.reverseOrder()); + public static void main(String[] args) throws Exception { + N = Integer.parseInt(br.readLine()); + long prevY = 0; + long accumulation = 0; //누적 이동거리 + for(int i = 1; i <= N; i++){ + st = new StringTokenizer(br.readLine()); + long curX = Long.parseLong(st.nextToken()); + long curY = Long.parseLong(st.nextToken()); + + maxheap.add(curY); //일단 maxheap에 넣음. + minheap.add(maxheap.poll()); + if(maxheap.size() < minheap.size()){ + maxheap.add(minheap.poll()); + } + if(i % 2 == 0){ + accumulation += (Math.abs(curX) + Math.abs(prevY - curY)); + prevY = maxheap.peek(); + }else{ + prevY = maxheap.peek(); + accumulation += (Math.abs(curX) + Math.abs(prevY - curY)); + } + bw.write(prevY + " " + accumulation + "\n"); + } + bw.close(); + } +} +```