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