문제

코드
import java.util.ArrayList;
import java.util.Scanner;
public class q1874 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<Integer> stack = new ArrayList<>();
        ArrayList<String> result = new ArrayList<>();
        int count = 1; 
        for(int i=0; i<N; i++) {
            try {
                int input = sc.nextInt();
                
                
                if(stack.size() == 0 || stack.get(stack.size()-1) < input) {
                    for(int j=count; j<=input; j++) {
                        stack.add(count);
                        count++;
                        result.add("+");
                    }
                    
                    stack.remove(stack.size()-1);
                    result.add("-");
                    
                
                } else if(stack.get(stack.size()-1) >= input) {
                    for(int j=stack.get(stack.size()-1); j>= input; j--) {
                        stack.remove(stack.size()-1);
                        result.add("-");
                    }
                }
            
            } catch(IndexOutOfBoundsException e) {
                System.out.println("NO");
                return;
            }
        }
        
        for(String res : result) {
            System.out.println(res);
        }
    }
}