-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.java
38 lines (30 loc) Β· 970 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package DP.P11055;
import java.io.*;
import java.util.*;
public class Main {
static int N;
static int[] A;
static int[] dp;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/DP/P11055/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
A = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++)
A[i] = Integer.parseInt(st.nextToken());
dp = new int[N];
int ans = 0;
for (int i = 0; i < N; i++) {
int max = 0;
for (int j = 0; j < i; j++) {
if (A[j] < A[i]) {
max = Math.max(max, dp[j]);
}
}
dp[i] = max + A[i];
ans = Math.max(ans, dp[i]);
}
System.out.println(ans);
}
}