-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.java
40 lines (30 loc) · 1.47 KB
/
program.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
import java.util.*;
public class OptimalFlightDistant {
public static void main(String[] args) {
System.out.println(getIdPairsForOptimal(
Arrays.asList(Arrays.asList(1, 3000), Arrays.asList(2, 5000), Arrays.asList(3, 7000),
Arrays.asList(4, 10000)),
Arrays.asList(Arrays.asList(1, 3000), Arrays.asList(2, 9000), Arrays.asList(3, 5000)), 10000));
}
public static List<List<Integer>> getIdPairsForOptimal(List<List<Integer>> forwardList,
List<List<Integer>> backwardList, int maxDistance) {
List<List<Integer>> result = new LinkedList<>();
List<List<Integer>> temp = new ArrayList<>();
int max = Integer.MIN_VALUE;
for (int i = 0; i < forwardList.size(); i++) {
for (int j = 0; j < backwardList.size(); j++) {
int cmax = forwardList.get(i).get(1) + backwardList.get(j).get(1);
if (cmax <= maxDistance) {
if (cmax > max) {
max = cmax;
result = new ArrayList<>();
result.add(Arrays.asList(forwardList.get(i).get(0), backwardList.get(j).get(0)));
} else if (cmax == max) {
result.add(Arrays.asList(forwardList.get(i).get(0), backwardList.get(j).get(0)));
}
}
}
}
return result;
}
}