From b3d832abbe563f6b9430c26f6e97fffc0d76d893 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 20 Mar 2025 15:15:06 +0900 Subject: [PATCH] =?UTF-8?q?[20250320]=20BOJ=20/=20G1=20/=20Lifeguards=20(S?= =?UTF-8?q?ilver)=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/20 BOJ G1 Lifeguards (Silver).md | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 khj20006/202503/20 BOJ G1 Lifeguards (Silver).md diff --git a/khj20006/202503/20 BOJ G1 Lifeguards (Silver).md b/khj20006/202503/20 BOJ G1 Lifeguards (Silver).md new file mode 100644 index 00000000..b9e74f1a --- /dev/null +++ b/khj20006/202503/20 BOJ G1 Lifeguards (Silver).md @@ -0,0 +1,80 @@ +```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 { + if(!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(); + for(int i=0;i T = new TreeSet<>(); + while(!Q.isEmpty()) { + int prev = T.size(); + if(prev == 1) len[T.first()] += Q.peek()[0]-pos; + if(prev > 0) tot += Q.peek()[0]-pos; + int now = Q.peek()[0]; + while(!Q.isEmpty() && Q.peek()[0] == now) { + int info = Q.peek()[1]; + if(info == 1) T.add(Q.poll()[2]); + else T.remove(Q.poll()[2]); + } + pos = now; + } + + int ans = 0; + for(int i=0;i