use proconio::{input, marker::Usize1}; fn main() { input! { n: usize, m: usize, t: i64, a: [Usize1; m], } let mut sum = vec![0; n]; a.iter().for_each(|&i| sum[i] += 1); println!( "{}", binary_search( |x| { sum.iter().fold(0, |time, &s| { if s >= x { time + s - x } else { time - (x - s) / t } }) <= 0 }, m as i64, 0 ) ); } fn binary_search(f: F, mut ok: i64, mut ng: i64) -> i64 where F: Fn(i64) -> bool, { while (ok - ng).abs() > 1 { let x = (ok + ng) / 2; if f(x) { ok = x; } else { ng = x; } } ok }