import java.util.*;
import java.math.*;
//rename the class name before submitting
public class EelAndRabbit {
public static void main(String[] args) {
EelAndRabbit obj = new EelAndRabbit();
System.out.println(
obj.getmax(
new int[] { 2, 4, 3, 2, 2, 1, 10 },
new int[] { 2, 6, 3, 7, 0, 2, 0 }
));
}
public int getmax(int[] l, int[] t) {
HashSet<Integer> times = new HashSet<Integer>();
for (int i = 0; i < t.length; i++) {
times.add(t[i]);
times.add(t[i] + l[i]);
}
ArrayList<Integer> T = new ArrayList<Integer>(times);
Collections.sort(T);
int maxEels = 0;
for (int i = 0; i < T.size(); i++) {
int t1 = T.get(i);
for (int j = i + 1; j < T.size(); j++) {
int t2 = T.get(j);
int numEels = 0;
for (int k = 0; k < l.length; k++) {
if (t1 >= t[k] && t1 <= t[k] + l[k]) {
numEels++;
}
else if (t2 >= t[k] && t2 <= t[k] + l[k]) {
numEels++;
}
}
maxEels = Math.max(maxEels, numEels);
}
}
return maxEels;
}
}
No comments:
Post a Comment