|
| 1 | +package backjoon; |
| 2 | +// https://www.acmicpc.net/problem/2565 |
| 3 | + |
| 4 | +import java.io.BufferedReader; |
| 5 | +import java.io.IOException; |
| 6 | +import java.io.InputStreamReader; |
| 7 | +import java.util.Arrays; |
| 8 | +import java.util.Comparator; |
| 9 | +import java.util.StringTokenizer; |
| 10 | + |
| 11 | +public class _2565 { |
| 12 | + public static void main(String[] args) throws IOException { |
| 13 | + |
| 14 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 15 | + int N = Integer.parseInt(br.readLine()); |
| 16 | + |
| 17 | + int[][] firstWire = new int[N][2]; |
| 18 | + int[] dp = new int[N]; |
| 19 | + |
| 20 | + StringTokenizer st; |
| 21 | + for(int i = 0; i < firstWire.length; i++) { |
| 22 | + st = new StringTokenizer(br.readLine()," "); |
| 23 | + firstWire[i][0] = Integer.parseInt(st.nextToken()); |
| 24 | + firstWire[i][1] = Integer.parseInt(st.nextToken()); |
| 25 | + } |
| 26 | + |
| 27 | + // ์ผ์ชฝ ์ ๋ด๋๋ฅผ ๊ธฐ์ค์ผ๋ก 2์ฐจ์ ๋ฐฐ์ด ์ ๋ ฌ |
| 28 | + Arrays.sort(firstWire, new Comparator <int[]>() { |
| 29 | + @Override |
| 30 | + public int compare(int[] o1, int[] o2) { |
| 31 | + return o1[0] - o2[0]; |
| 32 | + } |
| 33 | + }); |
| 34 | + |
| 35 | + for(int i=0; i<dp.length; i++){ |
| 36 | + dp[i] = 1; |
| 37 | + for(int j=0; j<i; j++){ |
| 38 | + if(firstWire[i][1] > firstWire[j][1]){ |
| 39 | + dp[i] = Math.max(dp[i], dp[j]+1); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + int max = 0; |
| 45 | + for(int i=0; i<N; i++){ |
| 46 | + max = Math.max(max, dp[i]); |
| 47 | + } |
| 48 | + |
| 49 | + // ์ ์ฒด ์ ์ ๊ฐ์ - ์ต๋ ์ค์น๊ฐ๋ฅ ๊ฐ์ = ์ต์ ์ฒ ๊ฑฐ๊ฐ๋ฅ ๊ฐ์ |
| 50 | + System.out.println(N-max); |
| 51 | + } |
| 52 | +} |
0 commit comments