문제 풀이/백준

[백준] 1668번. 트로피 진열(JAVA)

27200 2025. 6. 29. 17:04

문제

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


풀이(4분)

import java.io.*;
import java.util.*;

public class Main {

    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];

        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(br.readLine());
        }

        int leftMax = 0;
        int leftCount = 0;
        int rightMax = 0;
        int rightCount = 0;

        for(int i = 0; i < n; i++){
            if(arr[i] > leftMax){
                leftMax = arr[i];
                leftCount++;
            }
            if(arr[n-i-1] > rightMax){
                rightMax = arr[n-i-1];
                rightCount++;
            }
        }

        System.out.println(leftCount);
        System.out.println(rightCount);
    }
}

문제 풀이 전략

 

N의 범위가 50까지이므로 단순하게 배열을 저장한 뒤 좌우에서 최댓값을 추적하며, 갱신될 때만 +1 해주는 방식을 선택했다.