-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2565.java
More file actions
37 lines (31 loc) · 853 Bytes
/
2565.java
File metadata and controls
37 lines (31 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[][] = new int[n][2];
int dp[] = new int[n];
for (int i = 0; i < n; i++) {
dp[i]=1;
arr[i][0] = sc.nextInt();
arr[i][1] = sc.nextInt();
}
Arrays.sort(arr,(e1,e2)->{
return e1[0]-e2[0];
});
for(int i=0; i<n; i++){
for(int j=0; j<i; j++){
if(arr[j][1] < arr[i][1] && dp[i] < dp[j]+1){
dp[i]=dp[j]+1;
}
}
}
int max=0;
for(int i=0; i<n; i++){
if(max<dp[i])
max=dp[i];
}
System.out.println(n-max);
}
}