쵼쥬 2021. 12. 28. 17:25


내 코드

package com.company;

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

public class Main {
    static int N;
    static int max = 0;
    static ArrayList<Integer> list = new ArrayList<>();
    static int[] dp;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        N = Integer.parseInt(br.readLine());
        dp = new int[N];

        for (int i = 0; i < N; i++) {
            dp[i] = 1;
            list.add(Integer.parseInt(br.readLine()));

            for (int j = i - 1; j > -1; j--) {
                if (list.get(j) < list.get(i))
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
            }

            max = Math.max(max, dp[i]);
        }

        System.out.println(N - max);
    }
}