From 4ba77e7bf8c15eb2ea90f14e9e0580819dbdffb8 Mon Sep 17 00:00:00 2001 From: oncsr Date: Fri, 21 Mar 2025 16:47:51 +0900 Subject: [PATCH] =?UTF-8?q?[20250321]=20BOJ=20/=20G3=20/=20Painting=20the?= =?UTF-8?q?=20Fence=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202503/21 BOJ G3 Painting the Fence.md | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 khj20006/202503/21 BOJ G3 Painting the Fence.md diff --git a/khj20006/202503/21 BOJ G3 Painting the Fence.md b/khj20006/202503/21 BOJ G3 Painting the Fence.md new file mode 100644 index 00000000..f56bf312 --- /dev/null +++ b/khj20006/202503/21 BOJ G3 Painting the Fence.md @@ -0,0 +1,73 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N; + static PriorityQueue Q = new PriorityQueue<>((a,b) -> { + if(a[0] == b[0]) return b[1]-a[1]; + return a[0]-b[0]; + }); + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + int cur = 0; + for(int i=0;i 1) ans += now - prev; + while(!Q.isEmpty() && Q.peek()[0] == now) cnt += Q.poll()[1]; + prev = now; + } + bw.write(ans + "\n"); + + } + +} + +```