Problem:
Score : 700 points

Problem Statement

N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points.

M judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges,
and increase the score of each chosen problem by 1.

After all M judges cast their vote, the problems will be sorted in non-increasing order of score, and the first P problems will be chosen for the problemset.
Problems with the same score can be ordered arbitrarily, this order is decided by the chief judge.

How many problems out of the given N have a chance to be chosen for the problemset?

Constraints

2 \le N \le 10^5

1 \le M \le 10^9

1 \le V \le N - 1

1 \le P \le N - 1

0 \le A_i \le 10^9

Input

Input is given from Standard Input in the following format:

N M V P
A_1 A_2 ... A_N

Output

Print the number of problems that have a chance to be chosen for the problemset.

Sample Input 1

6 1 2 2
2 1 1 3 0 2

Sample Output 1

5

If the only judge votes for problems 2 and 5, the scores will be 2 2 1 3 1 2.
The problemset will consist of problem 4 and one of problems 1, 2, or 6.

If the only judge votes for problems 3 and 4, the scores will be 2 1 2 4 0 2.
The problemset will consist of problem 4 and one of problems 1, 3, or 6.

Thus, problems 1, 2, 3, 4, and 6 have a chance to be chosen for the problemset. On the contrary, there is no way for problem 5 to be chosen.

Sample Input 2

6 1 5 2
2 1 1 3 0 2

Sample Output 2

3

Only problems 1, 4, and 6 have a chance to be chosen.

Sample Input 3

10 4 8 5
7 2 3 6 1 6 5 4 6 5

Sample Output 3

8

Solution in Rust (1.15.1) (judge verdict: Accepted)

#[macro_use]
mod input_mcr {
    // ref: tanakh <https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8>
    // diff: using Parser
    #[macro_export(local_inner_macros)]
    macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut parser = Parser::from_str($s);
        input_inner!{parser, $($r)*}
    };
    (parser = $parser:ident, $($r:tt)*) => {
        input_inner!{$parser, $($r)*}
    };
    (new_stdin_parser = $parser:ident, $($r:tt)*) => {
        let stdin = std::io::stdin();
        let reader = std::io::BufReader::new(stdin.lock());
        let mut $parser = Parser::new(reader);
        input_inner!{$parser, $($r)*}
    };
    ($($r:tt)*) => {
        input!{new_stdin_parser = parser, $($r)*}
    };
}

    #[macro_export(local_inner_macros)]
    macro_rules! input_inner {
    ($parser:ident) => {};
    ($parser:ident, ) => {};
    ($parser:ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($parser, $t);
        input_inner!{$parser $($r)*}
    };
}

    #[macro_export(local_inner_macros)]
    macro_rules! read_value {
    ($parser:ident, ( $($t:tt),* )) => {
        ( $(read_value!($parser, $t)),* )
    };
    ($parser:ident, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($parser, $t)).collect::<Vec<_>>()
    };
    ($parser:ident, chars) => {
        read_value!($parser, String).chars().collect::<Vec<char>>()
    };
    ($parser:ident, char_) => {
        read_value!($parser, String).chars().collect::<Vec<char>>()[0]
    };
    ($parser:ident, usize1) => {
        read_value!($parser, usize) - 1
    };
    ($parser:ident, i64_) => {
        $parser.fast_i64()
    };
    ($parser:ident, usize_) => {
        $parser.fast_i64() as usize
    };
    ($parser:ident, usize1_) => {
        ($parser.fast_i64() - 1) as usize
    };
    ($parser:ident, $t:ty) => {
        $parser.next::<$t>().expect("Parse error")
    };
}

    use std::io;
    use std::io::BufRead;
    use std::str;

    // ref: tatsuya6502 <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e>
    // ref: wariuni <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e#comment-7040a5ae96305e884eb9>
    // diff: using std::io::BufRead::fill_buf()
    pub struct Parser<R> {
        pub reader: R,
        buf: Vec<u8>,
        pos: usize,
    }

    impl Parser<io::Empty> {
        pub fn from_str(s: &str) -> Parser<io::Empty> {
            Parser {
                reader: io::empty(),
                buf: s.as_bytes().to_vec(),
                pos: 0,
            }
        }
    }

    impl<R: BufRead> Parser<R> {
        pub fn new(reader: R) -> Parser<R> {
            Parser {
                reader: reader,
                buf: vec![],
                pos: 0,
            }
        }
        pub fn update_buf(&mut self) {
            self.buf.clear();
            self.pos = 0;
            loop {
                let (len, complete) = {
                    let buf2 = self.reader.fill_buf().unwrap();
                    self.buf.extend_from_slice(buf2);
                    let len = buf2.len();
                    (len, buf2[len - 1] <= 0x20)
                };
                self.reader.consume(len);
                if complete {
                    break;
                }
            }
        }
        pub fn next<T: str::FromStr>(&mut self) -> Result<T, T::Err> {
            loop {
                let mut begin = self.pos;
                while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                    begin += 1;
                }
                let mut end = begin;
                while end < self.buf.len() && (self.buf[end] > 0x20) {
                    end += 1;
                }
                if begin != self.buf.len() {
                    self.pos = end;
                    return unsafe { str::from_utf8_unchecked(&self.buf[begin..end]) }.parse::<T>();
                } else {
                    self.update_buf();
                }
            }
        }
        pub fn fast_i64(&mut self) -> i64 {
            loop {
                let mut begin = self.pos;
                while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                    begin += 1;
                }
                if begin == self.buf.len() {
                    self.update_buf();
                    continue;
                }
                let mut res = 0;
                let (is_positive, mut end) = match self.buf[begin] {
                    b'+' => (true, begin + 1),
                    b'-' => (false, begin + 1),
                    _ => (true, begin),
                };
                while end < self.buf.len() && (self.buf[end] > 0x20) {
                    res = res * 10 + (self.buf[end] as i64 - '0' as i64);
                    end += 1;
                }
                if begin != self.buf.len() {
                    self.pos = end;
                    return if is_positive { res } else { -res };
                } else {
                    self.update_buf();
                }
            }
        }
    }
}

use input_mcr::*;
use std::cmp::*;

use std::collections::BinaryHeap;

/*
#[derive(Debug)]
pub struct MinHeapWithOffset {
    q: MinHeap<i64>,
    offset: i64,
}

impl MinHeapWithOffset {
    pub fn new() -> MinHeapWithOffset {
        MinHeapWithOffset {
            q: BinaryHeap::new(),
            offset: 0,
        }
    }
    pub fn all_add(&mut self, x: i64) {
        self.offset += x;
    }
    pub fn min(&self) -> i64 {
        self.q.peek().unwrap().0 + self.offset
    }
    pub fn pop(&mut self) -> i64 {
        self.q.pop().unwrap().0 + self.offset
    }
    pub fn push(&mut self, x: i64) {
        self.q.push(Reverse(x - self.offset))
    }
}
*/

fn f(ys: &Vec<(usize, usize)>, n: usize, m: usize, v: usize, p: usize, i: usize) -> bool {
    if i < p {
        return true;
    }
    if i >= n {
        return false;
    }
    if ys[p - 1].0 > ys[i].0 + m {
        return false;
    }
    let mut zs = vec![];
    for k in p - 1..n {
        if k != i {
            zs.push(ys[i].0 + m - ys[k].0);
        }
    }
    zs.reverse();
    if (v - 1) <= (p - 1) {
        return true;
    }
    let w = (v - 1) - (p - 1);
    let mut rem = m as i64;
    //let mut q = MinHeapWithOffset::new();
    let mut t = 0;
    for &z in &zs {
        t += min(m, z);
    }
    return t >= w * m;
    /*
    if t >= w * m {

    }
    // eprintln!("zs = {:?}", zs);
    for i in 0..w {
        q.push(zs[i] as i64);
    }
    for i in w..zs.len() {
        // eprintln!("q = {:?}", q);
        if q.min() < 0 {
            return false;
        }
        let top = q.pop();
        q.all_add(top);
        rem -= top as i64;
        if rem <= 0 {
            return true;
        }
        q.push(zs[i] as i64);
    }
    false
    */
}

fn main() {
    input! {
        n: usize,
        m: usize,
        v: usize,
        p: usize,
        xs: [usize; n],
    }
    let mut ys: Vec<(usize, usize)> = xs.iter().enumerate().map(|(i, &x)| (x, i)).collect();
    ys.sort();
    ys.reverse();
    let mut res = 0;
    for i in (0..20).rev() {
        let t = res + (1 << i);
        // eprintln!("bin_t = {}", t);
        if f(&ys, n, m, v, p, t) {
            res = t;
        }
    }
    res += 1;
    /*
    let mut res = 0;
    res += p;
    let cu = {
        let mut cu = 0;
        for i in p-1..n {
            cu += ys[i].0;
        }
        cu
    };
    let border = ys[p-1].0;
    // eprintln!("border = {}", border);
    for i in p..n {
        if ys[i].0 + m >= border {
            if v-1 >= p-1 {
                let w_border_r = n - (v - 1 - (p-1));
                let w_border_l = w_border_r - 1;
                // eprintln!("w_l = {}, w_r = {}", w_border_l, w_border_r);
                if i <= w_border_l {
                    if w_border_r < n && ys[w_border_r].0 + 1 > ys[i].0 + m {
                        continue;
                    }
                }
                else {
                    if w_border_l < n && ys[w_border_l].0 + 1 > ys[i].0 + m {
                        continue;
                    }
                }
                let rem = (v-1 - (p-1)) * m;
                if (n-p) * (ys[i].0 + m) - (cu - ys[i].0) >= rem {
                    res += 1;
                }
            }
        }
    }
    */
    println!("{}", res);
}