Skip to content

Commit f02096c

Browse files
committed
Title: 자동차 단일 거래 이익 최대화하기, Time: 0ms, Memory: 0MB, Status: Passed - Codetree
1 parent 33ce504 commit f02096c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
 (0)