[백준] 2846번 : 오르막길 - Java(자바)

강재원·2022년 10월 7일
0

[코딩테스트] Java

목록 보기
109/200



https://www.acmicpc.net/problem/2846

import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
      Scanner s=new Scanner(System.in);
      int n=s.nextInt();
      int a=s.nextInt();
      int b=a;
      int max=0;
      for(int i=0;i<n-1;i++){
          int p=s.nextInt();
          if(p>b){
              b=p;
              if(b-a>max) max=b-a;
          }
          else{
              a=p;
              b=a;
          }
      }
      System.out.format("%d",max);
    }
}
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글