File tree Expand file tree Collapse file tree
260401/자동차 단일 거래 이익 최대화하기 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+ public static void main (String [] args ) throws Exception {
6+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
7+
8+ int N = Integer .parseInt (br .readLine ());
9+
10+ StringTokenizer st = new StringTokenizer (br .readLine ());
11+
12+ int [] arr = new int [N ];
13+ for (int i =0 ; i <N ; i ++){
14+ arr [i ] = Integer .parseInt (st .nextToken ());
15+ }
16+
17+ int [] min = new int [N ];
18+ min [0 ] = arr [0 ];
19+ for (int i =1 ; i <N ; i ++){
20+ min [i ] = Math .min (min [i -1 ], arr [i ]);
21+ }
22+
23+ int [] max = new int [N ];
24+ max [N -1 ] = arr [N -1 ];
25+ for (int i =N -2 ; i >=0 ; i --){
26+ max [i ] = Math .max (max [i +1 ], arr [i ]);
27+ }
28+
29+ int result = 0 ;
30+ for (int i =0 ; i <N ; i ++){
31+ result = Math .max (result , max [i ]-min [i ]);
32+ }
33+ System .out .println (result );
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments