use std::io; fn main() { let nm: Vec = { let mut s = String::new(); io::stdin().read_line(&mut s); s.trim().split_whitespace().map(|x| x.parse().unwrap()).collect() }; let n = nm[0]; let m = nm[1]; let k: u32 = { let mut s = String::new(); io::stdin().read_line(&mut s); s.trim().parse().unwrap() }; let mut a: Vec = { (1..n).into_iter().map(|_| { let mut s = String::new(); io::stdin().read_line(&mut s); s.trim().parse().unwrap() }).collect() }; a.sort(); let f = |i| { let us = k + a[i]; let mut gt_us = 0; let mut tail = a.len() - 1; if tail == i { tail -= 1; } for head in 0..a.len() { if head == i { continue; } if head >= tail { break; } if a[head] + a[tail] > us { gt_us += 1; if gt_us >= m { break; } tail -= 1; if tail == i { tail -= 1; } continue; } } if gt_us < m { return a[i] as i32; } return -1; }; if f(a.len() - 1) == -1 { println!("-1"); return; } { let t = f(0); if t != -1 { println!("{}", a[0]); return; } } let mut head = 0; let mut tail = a.len() - 1; loop { let x = (head + tail) / 2; println!("{} {} {}", head, x, tail); if tail - head < 2 { println!("{}", a[tail]); return; } let y = f(x); if y < m as i32 { head = x; } else { tail = x; } } }