From 0530f9816d48f3b934773d3d1fc05cb9fef70e21 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 18 Sep 2025 20:16:21 +0900 Subject: [PATCH] =?UTF-8?q?[20250918]=20BOJ=20/=20G4=20/=20=EB=93=A4?= =?UTF-8?q?=ED=8C=90=20=EA=B1=B4=EB=84=88=EA=B0=80=EA=B8=B0=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\353\204\210\352\260\200\352\270\260.md" | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "khj20006/202509/18 BOJ G4 \353\223\244\355\214\220 \352\261\264\353\204\210\352\260\200\352\270\260.md" diff --git "a/khj20006/202509/18 BOJ G4 \353\223\244\355\214\220 \352\261\264\353\204\210\352\260\200\352\270\260.md" "b/khj20006/202509/18 BOJ G4 \353\223\244\355\214\220 \352\261\264\353\204\210\352\260\200\352\270\260.md" new file mode 100644 index 00000000..50632f92 --- /dev/null +++ "b/khj20006/202509/18 BOJ G4 \353\223\244\355\214\220 \352\261\264\353\204\210\352\260\200\352\270\260.md" @@ -0,0 +1,86 @@ +```java +import java.io.*; +import java.util.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) + nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static int[] dp; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt()-1; + + dp = new int[101]; + Arrays.fill(dp, -1); + dp[io.nextInt()] = 0; + + while(N-->0) { + int a = io.nextInt(); + int max = 0; + for(int j=1;j<=100;j++) if(dp[j] != -1) max = Math.max(max, dp[j] + (j-a)*(j-a)); + dp[a] = Math.max(dp[a], max); + } + + int ans = 0; + for(int i=1;i<=100;i++) ans = Math.max(ans, dp[i]); + io.write(ans + "\n"); + + io.close(); + + } + +} +```