From fae79ff67582be40bb7b0bd54ceadb14c3014cb1 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Wed, 24 Dec 2025 13:28:26 +0900 Subject: [PATCH] =?UTF-8?q?[20251224]=20BOJ=20/=20G3=20/=20=EA=B0=80?= =?UTF-8?q?=EC=9E=A5=EB=86=92=EC=9D=80=ED=83=91=EC=8C=93=EA=B8=B0=20/=20?= =?UTF-8?q?=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\355\203\221\354\214\223\352\270\260.md" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "Ukj0ng/202512/24 BOJ G3 \352\260\200\354\236\245\353\206\222\354\235\200\355\203\221\354\214\223\352\270\260.md" diff --git "a/Ukj0ng/202512/24 BOJ G3 \352\260\200\354\236\245\353\206\222\354\235\200\355\203\221\354\214\223\352\270\260.md" "b/Ukj0ng/202512/24 BOJ G3 \352\260\200\354\236\245\353\206\222\354\235\200\355\203\221\354\214\223\352\270\260.md" new file mode 100644 index 00000000..52aaf5d7 --- /dev/null +++ "b/Ukj0ng/202512/24 BOJ G3 \352\260\200\354\236\245\353\206\222\354\235\200\355\203\221\354\214\223\352\270\260.md" @@ -0,0 +1,69 @@ +``` +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 Deque deque = new ArrayDeque<>(); + private static int[][] towers; + private static int[] dp, history; + private static int N; + + public static void main(String[] args) throws IOException { + init(); + + bw.write(deque.size() + "\n"); + while (!deque.isEmpty()) { + bw.write(deque.pollFirst() + "\n"); + } + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + towers = new int[N][4]; + dp = new int[N]; + history = new int[N]; + + Arrays.fill(history, -1); + + int len = 0; + int index = -1; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + towers[i][0] = Integer.parseInt(st.nextToken()); + towers[i][1] = Integer.parseInt(st.nextToken()); + towers[i][2] = Integer.parseInt(st.nextToken()); + towers[i][3] = i + 1; + } + + Arrays.sort(towers, (o1, o2) -> Integer.compare(o2[0], o1[0])); + + for (int i = 0; i < N; i++) { + dp[i] = towers[i][1]; + + for (int j = 0; j < i; j++) { + if (towers[j][2] > towers[i][2]) { + if (dp[j] + towers[i][1] > dp[i]) { + dp[i] = dp[j] + towers[i][1]; + history[i] = j; + } + } + } + if (dp[i] > len) { + len = dp[i]; + index = i; + } + } + + while (index != -1) { + deque.addLast(towers[index][3]); + index = history[index]; + } + } +} +```