-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLifeGuard.java
More file actions
55 lines (53 loc) · 1.16 KB
/
LifeGuard.java
File metadata and controls
55 lines (53 loc) · 1.16 KB
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
51
52
53
54
55
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class LifeGuard {
public static void main(String[] args) throws IOException
{
int[][] hours = null;
Scanner scan = new Scanner(new File("lifeguards.in"));
int num = scan.nextInt();
scan.nextLine();
hours = new int[num][2];
int beg, end;
int[] schedule = null;
int total = 0;
int max = 0;
for (int i = 0; i < num; i++)
{
beg = scan.nextInt();
end = scan.nextInt();
hours[i][0] = beg;
hours[i][1] = end;
}
for (int i = 0; i<hours.length; i++)
{
schedule = new int[1000];
total = 0;
for (int j = 0; j<hours.length; j++)
{
if(j == i)
continue;
beg = hours[j][0];
end = hours[j][1];
for (int k = beg; k <end; k++) //counting hours don't count last hour
{
if (schedule[k] != 1)
{
schedule[k] = 1;
total++;
}
}
}
if (total > max)
max = total;
}
PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("lifeguards.out")));
writer.println(max);
writer.close();
scan.close();
}
}