# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577063 | Benqt | Balloons (CEOI11_bal) | Java | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.*;
import java.util.*;
public class ballonsJavabrowtf {
public static void main(String[] args) throws IOException {
Kattio io = new Kattio();
int n = io.nextInt();
double[][] arr = new double[n][2];
for (int i=0; i<n; i++) {
arr[i][0] = io.nextDouble();
arr[i][1] = io.nextDouble();
}
Stack<double[]> st = new Stack<>();
for (int i=0; i<n; i++) {
while (!st.isEmpty()) {
double[] cur = st.peek();
double h = arr[i][0] - cur[0];
double r = (h * h)/(4 * cur[1]);
arr[i][1] = Math.min(arr[i][1], r);
if (r >= cur[1]) {
st.pop();
} else {
break;
}
}
st.add(arr[i]);
System.out.println(arr[i][1]);
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(new FileWriter(problemName + ".out"));
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) { }
return null;
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
}