Skip to content

Commit

Permalink
Create BOJ_11054.java
Browse files Browse the repository at this point in the history
  • Loading branch information
oxix97 authored Mar 19, 2024
1 parent e0be3b5 commit 079bbcc
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions jongchan/lee/BOJ_11054.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class BOJ_11054 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();
static StringTokenizer st;
static int N;
static int[] A, dp1, dp2;

public static void main(String[] args) throws IOException {
input();
solv();
br.close();
}

public static void solv() {
int sum = 0;
for (int i = 0; i < N; i++) {
dp1[i] = 1;
for (int j = 0; j < i; j++) {
if (A[i] > A[j] && dp1[i] <= dp1[j]) {
dp1[i] = dp1[j] + 1;
}
}
}

for (int i = N - 1; i >= 0; i--) {
dp2[i] = 1;
for (int j = N - 1; j > i; j--) {
if (A[i] > A[j] && dp2[i] <= dp2[j]) {
dp2[i] = dp2[j] + 1;
}
}
}

for (int i = 0; i < N; i++) {
sum = Math.max(sum, dp1[i] + dp2[i]);
}
System.out.println(sum - 1);
}

private static void input() throws IOException {
N = Integer.parseInt(br.readLine());
A = new int[N];
dp1 = new int[N];
dp2 = new int[N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
A[i] = Integer.parseInt(st.nextToken());
}
}
}

0 comments on commit 079bbcc

Please sign in to comment.