-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathH.java
59 lines (53 loc) · 1.79 KB
/
H.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
51
52
53
54
55
56
57
58
59
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;
public class H {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(new File("saloon.in"));
FileWriter fileWriter = new FileWriter(new File("saloon.out"));
int n = scanner.nextInt();
ArrayDeque<Integer> ochred = new ArrayDeque<>();
int len = 0;
for (int i = 0; i < n; i++) {
int hour = scanner.nextInt();
int min = scanner.nextInt();
int st = scanner.nextInt();
int timein = hour * 60 + min;
int timeout = 0;
if (len == 0) {
timeout = timein + 20;
ochred.addLast(timeout);
len++;
fileWriter.write(timeout / 60 + " " + timeout % 60 + "\n");
continue;
}
int f = ochred.getFirst();
if (timein >= f) {
while (len != 0 && timein >= ochred.getFirst()) {
ochred.removeFirst();
len--;
}
}
if (len == 0) {
timeout = timein + 20;
ochred.addLast(timeout);
len++;
fileWriter.write(timeout / 60 + " " + timeout % 60 + "\n");
continue;
}
if (st < len) {
fileWriter.write(hour + " " + min + " " + "\n");
continue;
}
int l = ochred.peekLast();
timeout = l + 20;
len++;
ochred.addLast(timeout);
fileWriter.write(timeout / 60 + " " + timeout % 60 + "\n");
}
fileWriter.flush();
}
}