File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
8+ static StringTokenizer st;
9+ static int N ;
10+ static int [] tops;
11+ static int [] decrease;
12+ static int [] increase;
13+
14+ public static void main (String [] args ) throws IOException {
15+ N = Integer . parseInt(br. readLine());
16+ tops = new int [N ];
17+ decrease = new int [N ];
18+ increase = new int [N ];
19+
20+ st = new StringTokenizer (br. readLine());
21+ for (int i = 0 ; i < N ; i++ ) {
22+ tops[i] = Integer . parseInt(st. nextToken());
23+ }
24+
25+ for (int i = 0 ; i < N ; i++ ) {
26+ decrease[i] = 1 ;
27+ for (int j = 0 ; j < i; j++ ) {
28+ if (tops[j] > tops[i] && decrease[i] < decrease[j] + 1 ) {
29+ decrease[i] = decrease[j] + 1 ;
30+ }
31+ }
32+ }
33+
34+ for (int i = N - 1 ; i >= 0 ; i-- ) {
35+ increase[i] = 1 ;
36+ for (int j = i + 1 ; j < N ; j++ ) {
37+ if (tops[i] < tops[j] && increase[i] < increase[j] + 1 ) {
38+ increase[i] = increase[j] + 1 ;
39+ }
40+ }
41+ }
42+
43+ int maxLen = 0 ;
44+ for (int i = 0 ; i < N ; i++ ) {
45+ maxLen = Math . max(maxLen, decrease[i] + increase[i] - 1 );
46+ }
47+
48+ bw. write(maxLen + " " );
49+ bw. close();
50+ }
51+ }
52+ ```
You can’t perform that action at this time.
0 commit comments