fn main() { let mut nm = String::new(); std::io::stdin().read_line(&mut nm).ok(); let nm: Vec = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nm[0]; let m = nm[1]; let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut upper = 1usize << 60; let mut lower = 0usize; while upper > lower { let middle = (upper + lower + 1) / 2; let mut carry = 0usize; let mut flg = true; for &v in a.iter() { if middle <= v { carry += v - middle; } else { if carry + v < middle { flg = false; break; } else { carry -= middle - v; } } } if !flg { upper = middle-1; } else { lower = middle; } } println!("{}", upper / m); }