File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ static class Wire implements Comparable<Wire > {
7+ int a, b;
8+ Wire (int a , int b ) {
9+ this . a = a;
10+ this . b = b;
11+ }
12+
13+ @Override
14+ public int compareTo (Wire o ) {
15+ return this . a - o. a;
16+ }
17+ }
18+
19+ public static void main (String [] args ) throws Exception {
20+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
21+ int N = Integer . parseInt(br. readLine());
22+
23+ Wire [] arr = new Wire [N ];
24+ int [] dp = new int [N ];
25+ for (int i = 0 ; i < N ; i++ ) {
26+ StringTokenizer st = new StringTokenizer (br. readLine());
27+ int a = Integer . parseInt(st. nextToken());
28+ int b = Integer . parseInt(st. nextToken());
29+ arr[i] = new Wire (a, b);
30+ }
31+
32+ Arrays . sort(arr);
33+
34+ int max = 1 ;
35+ for (int i = 0 ; i < N ; i++ ) {
36+ dp[i] = 1 ;
37+ for (int j = 0 ; j < i; j++ ) {
38+ if (arr[i]. b > arr[j]. b) {
39+ dp[i] = Math . max(dp[i], dp[j] + 1 );
40+ }
41+ }
42+ max = Math . max(max, dp[i]);
43+ }
44+ ```
45+ System . out. println(N - max);
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments