use std::io::*; use std::str::*; use std::cmp::*; use std::fmt; fn main() { let n:usize = read(); let m:i64 = read(); let mut a:Vec=vec![0;n-1]; let k:i32 = read(); for i in 0..(n-1){ let b:i32 = read(); a[i] = b; } a.sort(); let mut up:i32 = (n-1) as i32; let mut low:i32 = -1; let mut flag:bool = false; while up - low > 1{ let mut mid:usize = ((up+low)/2) as usize; let val = k + &a[mid]; let mut s:usize = 0; let mut t:usize = n - 2; let mut cnt = 0; //println!("#######{} {} {}######",mid,a[mid],cnt); for i in 0 .. ((n-2)/2){ if s == mid { s += 1; } if t == mid{ t -= 1; } // println!("{} {} {} {}",s,t,a[s]+a[t],val); if a[s] + a[t] > val { s += 1; t -= 1; cnt += 1; }else { if s + 1 == mid { s += 1; } s += 2; } } if cnt < m { up = mid as i32; flag = true; } else { low = mid as i32; } } println!("{}",(if flag { a[up as usize]}else{-1})); } fn read() -> T { let stdin = stdin(); let stdin = stdin.lock(); let s = stdin.bytes().map(|c| c.unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect::(); s.parse::().unwrap_or_else(|_| panic!("Faild to parse {}", s)) }