From 1ac8abf999eb195660eeb2b2bdaa7e1e971f7100 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sat, 20 Sep 2025 23:23:59 +0900 Subject: [PATCH] =?UTF-8?q?[20250920]=20BOJ=20/=20G4=20/=20=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=EC=BD=94=EC=8A=A4=ED=84=B0=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\354\275\224\354\212\244\355\204\260.md" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "lkhyun/202509/20 BOJ G4 \353\241\244\353\237\254\354\275\224\354\212\244\355\204\260.md" diff --git "a/lkhyun/202509/20 BOJ G4 \353\241\244\353\237\254\354\275\224\354\212\244\355\204\260.md" "b/lkhyun/202509/20 BOJ G4 \353\241\244\353\237\254\354\275\224\354\212\244\355\204\260.md" new file mode 100644 index 00000000..3a821839 --- /dev/null +++ "b/lkhyun/202509/20 BOJ G4 \353\241\244\353\237\254\354\275\224\354\212\244\355\204\260.md" @@ -0,0 +1,52 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N; + static int[] tops; + static int[] decrease; + static int[] increase; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + tops = new int[N]; + decrease = new int[N]; + increase = new int[N]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + tops[i] = Integer.parseInt(st.nextToken()); + } + + for (int i = 0; i < N; i++) { + decrease[i] = 1; + for (int j = 0; j < i; j++) { + if (tops[j] > tops[i] && decrease[i] < decrease[j] + 1) { + decrease[i] = decrease[j] + 1; + } + } + } + + for (int i = N - 1; i >= 0; i--) { + increase[i] = 1; + for (int j = i + 1; j < N; j++) { + if (tops[i] < tops[j] && increase[i] < increase[j] + 1) { + increase[i] = increase[j] + 1; + } + } + } + + int maxLen = 0; + for (int i = 0; i < N; i++) { + maxLen = Math.max(maxLen, decrease[i] + increase[i] - 1); + } + + bw.write(maxLen + ""); + bw.close(); + } +} +```