백준 #1668번 트로피 진열

jhj·2025년 1월 19일

백준 JAVA

목록 보기
565/583
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] size = new int[n];
		
		for(int i = 0; i < n; i++) {
			size[i] = sc.nextInt();
		}
		
		int left = 1;
		int leftMax = size[0];
		for(int i = 0; i < n; i++) {
			if(leftMax < size[i]) {
				left++;
				leftMax = size[i];
			}
		}
		
		int right = 1;
		int rightMax = size[size.length - 1];
		for(int i = size.length - 1; i >= 0; i--) {
			if(rightMax < size[i]) {
				right++;
				rightMax = size[i];
			}
		}
		System.out.println(left);
		System.out.println(right);
		sc.close();
	}
}
profile
개발자를 꿈꾸는

0개의 댓글