-
Notifications
You must be signed in to change notification settings - Fork 0
/
Last moment before all ants fall out of a plank
68 lines (54 loc) · 1.85 KB
/
Last moment before all ants fall out of a plank
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
60
61
62
63
64
65
66
67
68
//Last moment before all ants fall out of a plank
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCases = Integer.parseInt(sc.nextLine().trim());
while(testCases-- > 0) {
int n = Integer.parseInt(sc.nextLine().trim());
String temp = sc.nextLine().trim();
String[] leftInput = temp.split(" ");
int left[];
if(leftInput.length == 1 && leftInput[0].isEmpty()) {
left = new int[0];
}
else {
left = new int[leftInput.length];
for(int i = 0; i < left.length; i++) {
left[i] = Integer.parseInt(leftInput[i]);
}
}
temp = sc.nextLine().trim();
String[] rightInput = temp.split(" ");
int right[];
if(rightInput.length == 1 && rightInput[0].isEmpty()) {
right = new int[0];
}
else {
right = new int[rightInput.length];
for(int i = 0; i < right.length; i++) {
right[i] = Integer.parseInt(rightInput[i]);
}
}
Solution sol = new Solution();
int lastMoment = sol.getLastMoment(n, left, right);
System.out.println(lastMoment);
System.out.println("~");
}
sc.close();
}
}
class Solution {
public int getLastMoment(int n, int left[], int right[]) {
int res = 0;
for(int i = 0; i < left.length; i++) {
res = Math.max(res, left[i]);
}
for(int i = 0; i < right.length; i++) {
res = Math.max(res, n - right[i]);
}
return res;
}
}