Skip to content

Commit b16ea82

Browse files
authored
Merge pull request #918 from AlgorithmWithGod/khj20006
[20250918] BOJ / G4 / 들판 건너가기 / 권혁준
2 parents d9da598 + 0530f98 commit b16ea82

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
class IOController {
6+
BufferedReader br;
7+
BufferedWriter bw;
8+
StringTokenizer st;
9+
10+
public IOController() {
11+
br = new BufferedReader(new InputStreamReader(System.in));
12+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
13+
st = new StringTokenizer("");
14+
}
15+
16+
String nextLine() throws Exception {
17+
String line = br.readLine();
18+
st = new StringTokenizer(line);
19+
return line;
20+
}
21+
22+
String nextToken() throws Exception {
23+
while (!st.hasMoreTokens())
24+
nextLine();
25+
return st.nextToken();
26+
}
27+
28+
int nextInt() throws Exception {
29+
return Integer.parseInt(nextToken());
30+
}
31+
32+
long nextLong() throws Exception {
33+
return Long.parseLong(nextToken());
34+
}
35+
36+
double nextDouble() throws Exception {
37+
return Double.parseDouble(nextToken());
38+
}
39+
40+
void close() throws Exception {
41+
bw.flush();
42+
bw.close();
43+
}
44+
45+
void write(String content) throws Exception {
46+
bw.write(content);
47+
}
48+
49+
}
50+
51+
public class Main {
52+
53+
static IOController io;
54+
55+
//
56+
57+
static int N;
58+
static int[] dp;
59+
60+
public static void main(String[] args) throws Exception {
61+
62+
io = new IOController();
63+
64+
N = io.nextInt()-1;
65+
66+
dp = new int[101];
67+
Arrays.fill(dp, -1);
68+
dp[io.nextInt()] = 0;
69+
70+
while(N-->0) {
71+
int a = io.nextInt();
72+
int max = 0;
73+
for(int j=1;j<=100;j++) if(dp[j] != -1) max = Math.max(max, dp[j] + (j-a)*(j-a));
74+
dp[a] = Math.max(dp[a], max);
75+
}
76+
77+
int ans = 0;
78+
for(int i=1;i<=100;i++) ans = Math.max(ans, dp[i]);
79+
io.write(ans + "\n");
80+
81+
io.close();
82+
83+
}
84+
85+
}
86+
```

0 commit comments

Comments
 (0)