use std::io::*; use std::str::FromStr; fn main() { let inputs = (0..4).map(|_| read()).collect::>(); exec(inputs); } fn exec(inputs: Vec) { if inputs[1] / inputs[2] <= inputs[0] { rec_yasai(inputs[1] / inputs[2], inputs); } else { rec_yasai(inputs[0], inputs); } } fn rec_yasai(max_yasai: i64, inputs: Vec) { let niku = inputs[2] * max_yasai; if max_yasai == 0 || niku <= inputs[1] || max_yasai + niku < inputs[3] { return println!("{}", max_yasai); } else { rec_yasai(max_yasai - 1, inputs); } } fn read() -> T { let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") }