54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
use std::io::{read_to_string, stdin};
|
|
|
|
fn main() {
|
|
let temp = read_to_string(stdin()).unwrap();
|
|
let mut iter = temp
|
|
.split_ascii_whitespace()
|
|
.map(|x| x.parse::<usize>().unwrap());
|
|
|
|
let n = iter.next().unwrap();
|
|
let m = iter.next().unwrap();
|
|
|
|
let mut arr = (0..n).map(|_| iter.next().unwrap()).collect::<Vec<_>>();
|
|
arr.sort();
|
|
|
|
let mut lo = 0;
|
|
let mut hi = *arr.last().unwrap();
|
|
|
|
let mut cum = vec![0];
|
|
for &e in arr.iter() {
|
|
cum.push(cum.last().unwrap() + e);
|
|
}
|
|
|
|
while hi >= lo && hi - lo > 1 {
|
|
let mid = (hi + lo) / 2;
|
|
let key = arr.binary_search(&mid);
|
|
|
|
let s = match key {
|
|
Ok(idx) => cum[n] - cum[idx] - (n - idx) * mid,
|
|
Err(idx) => cum[n] - cum[idx] - (n - idx) * mid,
|
|
};
|
|
if s < m {
|
|
hi = mid - 1;
|
|
} else {
|
|
if lo == mid {
|
|
hi = lo;
|
|
}
|
|
lo = mid;
|
|
}
|
|
}
|
|
|
|
{
|
|
let key = arr.binary_search(&hi);
|
|
let s = match key {
|
|
Ok(idx) => cum[n] - cum[idx] - (n - idx) * hi,
|
|
Err(idx) => cum[n] - cum[idx] - (n - idx) * hi,
|
|
};
|
|
if s >= m {
|
|
println!("{}", hi);
|
|
} else {
|
|
println!("{}", lo);
|
|
}
|
|
}
|
|
}
|