-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlifeguards.java
50 lines (40 loc) · 1.35 KB
/
lifeguards.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.*;
import java.util.*;
/**
* Created by supersteve on 1/14/18.
*/
public class lifeguards {
public static void main(String[] args) throws IOException {
// write your code here
BufferedReader f = new BufferedReader(new FileReader("lifeguards.in"));
// input file name goes above
int n = Integer.parseInt(f.readLine());
int[][] indexes = new int[n][2];
int[] stuff = new int[10001];
int sum = 0;
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(f.readLine());
indexes[i][0] = Integer.parseInt(st.nextToken());
indexes[i][1] = Integer.parseInt(st.nextToken());
for (int j = indexes[i][0]; j < indexes[i][1]; j++) {
if (stuff[j] == 0) {
sum++;
}
stuff[j]++;
}
}
int min = Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
int curnum = 0;
for (int j = indexes[i][0]; j < indexes[i][1]; j++) {
if (stuff[j] == 1) {
curnum++;
}
}
min = Math.min(min,curnum);
}
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("lifeguards.out")));
out.println(sum-min);
out.close();
}
}