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 C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

#if 0
#define MAX (1 << 17) /* 131072 */

int ki[MAX * 2 - 1];
int ki_all[MAX * 2 - 1];

void add_i(int idx, int qmin, int qmax, int qdelta, int smin, int smax) {
	if (qmax <= smin || smax <= qmin) { /* クエリがセグメントから完全に外れている */
		/* NOP */
	} else if(qmin <= smin && smax <= qmax) { /* セグメントがクエリに完全に含まれる */
		ki_all[idx] += qdelta;
	} else {
		int smid = smin + (smax - smin) / 2;
		int li = idx * 2 + 1, ri = idx * 2 + 2;
		int l, r;
		ki_all[li] += ki_all[idx];
		ki_all[ri] += ki_all[idx];
		ki_all[idx] = 0;
		add_i(li, qmin, qmax, qdelta, smin, smid);
		add_i(ri, qmin, qmax, qdelta, smid, smax);
		l = ki[li] + ki_all[li];
		r = ki[ri] + ki_all[ri];
		ki[idx] = l >= r ? l : r;
	}
}

void add(int min, int max, int delta) {
	add_i(0, min, max, delta, 0, MAX);
}

int get_i(int idx, int qmin, int qmax, int smin, int smax) {
	if (qmax <= smin || smax <= qmin) { /* クエリがセグメントから完全に外れている */
		return -1;
	} else if(qmin <= smin && smax <= qmax) { /* セグメントがクエリに完全に含まれる */
		return ki[idx] + ki_all[idx];
	} else {
		int smid = smin + (smax - smin) / 2;
		int l, r;
		l = get_i(idx * 2 + 1, qmin, qmax, smin, smid);
		r = get_i(idx * 2 + 2, qmin, qmax, smid, smax);
		return (l >= r ? l : r) + ki_all[idx];
	}
}

int get(int min, int max) {
	return get_i(0, min, max, 0, MAX);
}

void init(void) {
	memset(ki, 0, sizeof(ki));
	memset(ki_all, 0, sizeof(ki_all));
}
#endif

int cmp(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a > b ? -1 : a < b;
}

int N, M, V, P;
int A[114514];

int main(void) {
	int i;
	int kotae, kotae2;
	int maki;
	int ng, ok;
	if (scanf("%d%d%d%d", &N, &M, &V, &P) != 4) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}
	qsort(A, N, sizeof(*A), cmp);
	maki = V - (P - 1) - 1;
	if (maki < 0) maki = 0;
	kotae = P;
	while (kotae < N - maki) {
		int kugyu = A[kotae];
		if (A[kotae] + M >= A[P - 1]) {
			kotae++;
		} else {
			printf("%d\n", kotae);
			return 0;
		}
		while (kotae < N && A[kotae] == kugyu) kotae++;
	}
#if 0
	printf("%d\n", maki);
#endif
	ng = N;
	ok = P - 1;
	while (ok + 1 < ng) {
		int mid = ok + (ng - ok) / 2;
		if (mid < P) ok = mid;
		else if (N <= mid) ng = mid;
		else {
#if 0
			int left = M, current = P;
			init();
			for (i = P; i < N; i++) {
				add(i, i + 1, i == mid ? -999999999 : A[i]);
			}
			printf("%d %d %d\n", ok, ng, mid);
			while (left > 0) {
				int qmin = current, qmax = current + maki + (current + maki >= mid);
				int maxValue = get(current, N);
				printf("%d %d\n", current, maxValue);
				if (maxValue >= A[P - 1]) {
					current++;
				} else if (qmax <= N) {
					int delta = A[P - 1] - maxValue;
					if (delta > left) delta = left;
					add(qmin, qmax, delta);
					left -= delta;
					current++;
				} else {
					break;
				}
			}
#else
			int64_t left = (int64_t)M * maki;
			for (i = P; i < N; i++) {
				if (i != mid) {
					int delta = A[P - 1] - A[i];
					if (delta > M) delta = M;
					if (i > mid && delta < M) delta = M;
					if (delta > left) delta = left;
					left -= delta;
				}
			}
#endif
			if (left > 0) ng = mid; else ok = mid;
		}
	}
	
	kotae2 = ok + 1;
	while (kotae2 >= P && A[kotae2 - 1] + M < A[P - 1]) kotae2--;
	printf("%d\n", kotae > kotae2 ? kotae : kotae2);
	return 0;
}

/*
下位の問題に投票しまくって投票されないやつを抜けるか？

入力例3

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

↓

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

抜かすことを狙わないやつには投票することで、下位への投票数を減らせる

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

10 5 6 1
10 9 9 9 9 9 9 9 9 9

----------------------------------------

抜かしたい場所より上 → OK
抜かしたい場所より下 → OK
抜かしたい場所の中間 → 抜かしたい場所を超えない程度までOK

*****##
****
***#
***#
**##

5 2 3 2
5 4 3 3 2

分割して逃がすことが可能！

逃がすとは？
・M*makiを埋める
・1箇所にMを超えて突っ込んではいけない

*/