File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-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+
7+ static List<Deque<Integer > > wheel = new ArrayList<> ();
8+
9+ public static void main (String [] args ) throws Exception {
10+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
11+ StringTokenizer st;
12+
13+ int n = Integer . parseInt(br. readLine());
14+ int [] arr = new int [n];
15+ int [] dp = new int [n];
16+ st = new StringTokenizer (br. readLine());
17+ for (int i = 0 ; i < n; i++ ) {
18+ arr[i] = Integer . parseInt(st. nextToken());
19+ }
20+
21+ for (int i = 0 ; i < n; i++ ) {
22+ int max = arr[i];
23+ int min = arr[i];
24+ for (int j = i; j >= 0 ; j-- ) {
25+ max = Math . max(max, arr[j]);
26+ min = Math . min(min, arr[j]);
27+ if (j == 0 ) {
28+ dp[i] = Math . max(dp[i], max - min);
29+ } else {
30+ dp[i] = Math . max(dp[i], dp[j - 1 ] + (max - min));
31+ }
32+ }
33+ }
34+
35+ System . out. println(dp[n - 1 ]);
36+ }
37+ }
38+ ```
You can’t perform that action at this time.
0 commit comments