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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		long M = GetLong();
		long V = GetLong();
		long P = GetLong();
		long[] A = GetLongs((int)N);

		Array.Sort(A);
		Array.Reverse(A);

		var lst = new LazySegmentTree((int)N);
		int last = Array.FindLastIndex(A, x => x == A[P - 1]);
		lst.RangeUpdate(0, last + 1, 1);

		for(int i = 0; i < P; i++)
		{
			long grp = A[i];
			long grpCnt = 1;
			while(i + 1 < N && A[i + 1] == grp)
			{
				i++;
				grpCnt++;
			}
			if(grpCnt + V > N)
				continue;

			long min = Min(grp, A[P - 1] + M);
			int r = right(A, P, M, min);
			lst.RangeUpdate((int)P - 1, Min((int)(P + grpCnt + 1), r + 1), 1);			
		}

		WriteLine(lst.Query(0, (int)N));
	}

	private int right(long[] A, long P, long M, long min)
	{
		int ng = A.Length;
		int ok = (int)P - 1;
		while(Abs(ng - ok) > 1)
		{
			int mid = (ng + ok) / 2;
			if(A[mid] + M >= min)
				ok = mid;
			else
				ng = mid;
		}
		return ok;
	}
}

public class LazySegmentTree
{
	private int N;
	private long[] dat;
	private long[] lazy;
	private bool[] isLazy;

	public LazySegmentTree(int n)
	{
		N = 1;		
		while(N < n)
			N <<= 1;
			
		dat = new long[2 * N - 1];
		for(int i = 0; i < 2 * N - 1; i++)
			dat[i] = 0;

		lazy = new long[2 * N - 1];
		isLazy = new bool[2 * N - 1];
	}

	private void eval(int k, int l, int r)
	{
		if(!isLazy[k])
			return;

		dat[k] = lazy[k];

		// propagate to children
		if(r - l > 1)
		{
			lazy[2 * k + 1] = lazy[k] / 2;
			lazy[2 * k + 2] = lazy[k] / 2;
			isLazy[2 * k + 1] = true;
			isLazy[2 * k + 2] = true;
		}
		
		isLazy[k] = false;
	}

	public void RangeUpdate(int a, int b, long x, int k = 0, int l = 0, int r = -1)
	{
		if(r == -1)
			r = N;

		// evaluate propagation from parent
		eval(k, l, r);

		if(b <= l || r <= a)
			return;

		if(a <= l && r <= b)
		{
			// update
			lazy[k] = (long)(r - l) * x;
			isLazy[k] = true;
			eval(k, l, r);
		}
		else
		{
			RangeUpdate(a, b, x, 2 * k + 1, l, (l + r) / 2);
			RangeUpdate(a, b, x, 2 * k + 2, (l + r) / 2, r);
			dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
		}
	}

	public long Query(int a, int b, int k = 0, int l = 0, int r = -1)
	{
		if(r == -1)
			r = N;

		if(r <= a || b <= l)
			return 0;

		eval(k, l, r);

		if(a <= l && r <= b)
			return dat[k];
		else
		{
			long vl = Query(a, b, k * 2 + 1, l, (l + r) / 2);
			long vr = Query(a, b, k * 2 + 2, (l + r) / 2, r);
			return vl + vr;
		}
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}