in contests/zone2021/zone2021_b.rs [17:48]
fn solve(src: &str) -> String {
let source = AutoSource::from(src);
input! {
from source,
N: usize,
D: usize,
H: usize,
mut dhs: [[usize; 2]; N]
}
dhs.sort(); // dの昇順
let mut sieta = atan(H as f64 / D as f64);
let mut H_now: f64 = H as f64;
for dh in dhs {
let d: f64 = dh[0] as f64;
let h: f64 = dh[1] as f64;
let height = tan(sieta) * d;
if height.round() < h.round() {
let local_sieta = atan((H as f64 - h) / (D as f64 - d));
let buf = h - tan(local_sieta) * d;
H_now += buf;
sieta = atan(D as f64 / H_now);
}
}
let answer = H_now - H as f64;
format!("{:.4}", answer)
}