문제링크
https://www.acmicpc.net/problem/2846
package BOJ;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main_2846 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int arr[] = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=0;i<N;i++) arr[i] = Integer.parseInt(st.nextToken());
int min=Integer.MAX_VALUE;
int res = Integer.MIN_VALUE;
for(int i=0;i<N-1;i++){
if(arr[i]<arr[i+1]){
min = Math.min(min,arr[i]);
res = Math.max(res,arr[i+1]-min);
}
else{
min = Integer.MAX_VALUE;
}
}
System.out.println((res==Integer.MIN_VALUE)?"0":res);
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[JAVA]백준_6118_숨바꼭질 (0) | 2021.06.01 |
---|---|
[JAVA]백준_2877_4와7 (0) | 2021.05.03 |
[JAVA]백준_2075_N번째 큰 수 (0) | 2021.04.27 |
[JAVA]백준_2660_회장뽑기 (0) | 2021.04.22 |
[JAVA]백준_1956_운동 (0) | 2021.04.21 |