From 80b1ccbefedf1c6937af5111b67683f10532623b Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Mon, 29 Sep 2025 22:54:48 +0900 Subject: [PATCH] =?UTF-8?q?[20250929]=20BOJ=20/=20G5=20/=20=ED=8F=AC?= =?UTF-8?q?=EC=8A=A4=ED=83=9D=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5 \355\217\254\354\212\244\355\203\235.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "Ukj0ng/202509/29 BOJ G5 \355\217\254\354\212\244\355\203\235.md" diff --git "a/Ukj0ng/202509/29 BOJ G5 \355\217\254\354\212\244\355\203\235.md" "b/Ukj0ng/202509/29 BOJ G5 \355\217\254\354\212\244\355\203\235.md" new file mode 100644 index 00000000..dbf5e284 --- /dev/null +++ "b/Ukj0ng/202509/29 BOJ G5 \355\217\254\354\212\244\355\203\235.md" @@ -0,0 +1,60 @@ +``` +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 Stack[] stacks; + private static int N; + + public static void main(String[] args) throws IOException { + init(); + + int answer = 0; + for (int i = 0; i < 4; i++) { + answer += stacks[i].size(); + } + + if (answer-4 == N) bw.write("YES"); + else bw.write("NO"); + + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + stacks = new Stack[4]; + + for (int i = 0; i < 4; i++) { + stacks[i] = new Stack<>(); + stacks[i].push(0); + } + + N = Integer.parseInt(br.readLine()); + StringTokenizer st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < N; i++) { + int num = Integer.parseInt(st.nextToken()); + int min = N; + int index = -1; + + for (int j = 0; j < 4; j++) { + if (stacks[j].peek() == 0) { + index = j; + continue; + } + int temp = num - stacks[j].peek(); + if (temp < 0) continue; + if (temp < min) { + index = j; + min = temp; + } + } + + if (index > -1) stacks[index].push(num); + } + } +} +```