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)

use std::collections::BTreeMap;

const INF: usize = 1e15 as usize;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let vote: usize = sc.read();
    let p: usize = sc.read();

    let mut count = BTreeMap::new();
    for _ in 0..n {
        let a: usize = sc.read();
        *count.entry(a).or_insert(0) += 1;
    }

    let mut p_th = INF;
    {
        let mut c = 0;
        for (&a, &count) in count.iter().rev() {
            c += count;
            if c >= p {
                p_th = a;
                break;
            }
        }
    }
    assert_ne!(p_th, INF);
    //    eprintln!("{}", p_th);

    let mut ans = 0;
    let mut ceil_count = 0;
    let mut sum = 0;
    let mut sum_count = 0;
    for (a, count) in count.into_iter().rev() {
        //        println!(
        //            "a={} count={} ceil_count={} sum={} sum_count={}",
        //            a, count, ceil_count, sum, sum_count
        //        );
        if a + m < p_th {
            break;
        }
        if ceil_count + count <= p - 1 {
            ans += count;
            ceil_count += count;
        } else if ceil_count < p - 1 {
            let space = p - 1 - ceil_count;
            ceil_count += space;
            let remain = count - space;
            assert!(remain > 0);
            sum += remain * a;
            sum_count += remain;
            ans += count;
        } else {
            assert_eq!(ceil_count, p - 1);
            let already = n - sum_count;
            if already >= vote {
                ans += count;
            } else {
                let remain_vote = vote - already;
                let remaining = remain_vote * m;
                let height = a + m;
                let rectangle = height * sum_count;
                if remaining + sum <= rectangle {
                    ans += count;
                }
            }
            sum_count += count;
            sum += a * count;
        }
    }

    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}