-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrange.java
More file actions
36 lines (27 loc) · 922 Bytes
/
Copy pathrange.java
File metadata and controls
36 lines (27 loc) · 922 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
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] ranges = new int[n][2];
for (int i = 0; i < n; i++) {
ranges[i][0] = sc.nextInt(); // l
ranges[i][1] = sc.nextInt(); // r
}
int maxGood = 0;
for (int i = 0; i < n; i++) {
int count = 1; // include range i itself
int l1 = ranges[i][0], r1 = ranges[i][1];
for (int j = 0; j < n; j++) {
if (i == j) continue;
int l2 = ranges[j][0], r2 = ranges[j][1];
if (Math.max(l1, l2) <= Math.min(r1, r2)) {
count++;
}
}
maxGood = Math.max(maxGood, count);
}
int answer = n - maxGood;
System.out.println(answer);
}
}