From de7e0c63c1cbeb96d65b770ae2fc026d886421c7 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sat, 25 Oct 2025 13:28:11 +0900 Subject: [PATCH] =?UTF-8?q?[20251025]=20BOJ=20/=20G1=20/=20=EC=8A=A4?= =?UTF-8?q?=EC=B9=B4=EC=9D=B4=EB=9D=BC=EC=9D=B8=20/=20=ED=95=9C=EC=A2=85?= =?UTF-8?q?=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\354\235\264\353\235\274\354\235\270.md" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "Ukj0ng/202510/25 BOJ G1 \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270.md" diff --git "a/Ukj0ng/202510/25 BOJ G1 \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270.md" "b/Ukj0ng/202510/25 BOJ G1 \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270.md" new file mode 100644 index 00000000..6f1bd077 --- /dev/null +++ "b/Ukj0ng/202510/25 BOJ G1 \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270.md" @@ -0,0 +1,81 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static TreeMap buildings; + private static List events; + private static int N; + + public static void main(String[] args) throws IOException { + init(); + + int height = 0; + for (Event event : events) { + if (event.flag) { + buildings.put(event.height, buildings.getOrDefault(event.height, 0)+1); + if (height < buildings.lastKey()) { + height = buildings.lastKey(); + bw.write(event.x + " " + height + " "); + } + } else { + buildings.put(event.height, buildings.get(event.height)-1); + if (buildings.get(event.height) == 0) buildings.remove(event.height); + if (height > buildings.lastKey()) { + height = buildings.lastKey(); + bw.write(event.x + " " + height + " "); + } + } + } + + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + + events = new ArrayList<>(); + buildings = new TreeMap<>(); + buildings.put(0, 1); + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int l = Integer.parseInt(st.nextToken()); + int h = Integer.parseInt(st.nextToken()); + int r = Integer.parseInt(st.nextToken()); + + events.add(new Event(l, h, true)); + events.add(new Event(r, h, false)); + } + + events.sort((o1, o2) -> { + if (o1.x != o2.x) return Integer.compare(o1.x, o2.x); + + if (o1.flag != o2.flag) { + return o1.flag ? -1 : 1; + } + + if (o1.flag) { + return Integer.compare(o2.height, o1.height); + } + return Integer.compare(o1.height, o2.height); + }); + } + + static class Event { + int x; + int height; + boolean flag; + + public Event(int x, int height, boolean flag) { + this.x = x; + this.height = height; + this.flag = flag; + } + } +} +```