import java.io.*;
import java.util.*;
public class mobile {
public static int n, l;
public static double[][] points;
public static double alpha = 0.0001;
public static void main(String[] args) throws IOException {
BufferedReader fin = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader fin = new BufferedReader(new FileReader("G:\\My Drive\\USACO Problems\\Problems\\test.in"));
PrintWriter fout = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(fin.readLine());
n = Integer.parseInt(st.nextToken());
l = Integer.parseInt(st.nextToken());
points = new double[n][2];
for (int i=0; i<n; i++) {
st = new StringTokenizer(fin.readLine());
points[i][0] = Integer.parseInt(st.nextToken());
points[i][1] = Integer.parseInt(st.nextToken());
}
//fout.println(Arrays.toString(findRange(2, 5)));
double low = 0.0;
double high = 10000000005.0;
while (!equal(low, high)) {
double mid = (low+high)/2;
//fout.println(mid);
if (works(mid)) {
high = mid;
}
else {
low = mid+alpha;
}
}
fout.printf("%.5f%n", low);
fin.close();
fout.close();
}
public static boolean equal(double a, double b) {
return Math.abs(b-a) <= alpha;
}
public static boolean works(double r) {
double[][] ranges = new double[n][2];
for (int i=0; i<n; i++) {
double[] d = findRange(i, r);
ranges[i][0] = d[0];
ranges[i][1] = d[1];
}
Arrays.sort(ranges, (double[] a, double[] b) -> Double.compare(a[0], b[0]));
//System.out.println(Arrays.deepToString(ranges));
for (int i=1; i<n; i++) {
if (ranges[i][0] > ranges[i-1][1]) {
return false;
}
if (Double.isNaN(ranges[i][0]) || Double.isNaN(ranges[i][1])) {
ranges[i][0] = ranges[i-1][0];
ranges[i][1] = ranges[i-1][1];
}
else {
ranges[i][0] = ranges[i-1][0];
ranges[i][1] = Math.max(ranges[i-1][1], ranges[i][1]);
}
}
if (ranges[n-1][0] > 0 || ranges[n-1][1] < l) {
return false;
}
return true;
}
public static double[] findRange(int i, double r) {
double yDist = Math.abs(points[i][1]);
double xDist = Math.sqrt(r*r-yDist*yDist);
return new double[]{points[i][0]-xDist, points[i][0]+xDist};
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |