use std::io::*; fn f(a: &[f64], b: f64, x: f64) -> f64 { let mut cnt1 = 0.0; let mut cnt2 = 0.0; for i in 0..a.len() { if a[i] > x { cnt1 += a[i] - x; } else { cnt2 += x - a[i]; } } if cnt1 + b >= cnt2 { cnt1 + cnt2 } else { 1e12 } } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let b: f64 = itr.next().unwrap().parse().unwrap(); let n: usize = itr.next().unwrap().parse().unwrap(); let c: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let mut l = 0.0; let mut r = 1e10; for _ in 0..1000 { let x1 = (l + l + r) / 3.0; let x2 = (l + r + r) / 3.0; let y1 = f(&c, b, x1); let y2 = f(&c, b, x2); if y1 > y2 { l = x1; } else { r = x2; } } println!("{}", f(&c, b, l.round()) as u64); }