qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, V: int, P: int, A: "List[int]"):
    P -= 1
    A = sorted(A, reverse=True)

    result = 0
    for n in range(N):
        if n < P:
            result += 1
        elif A[n] + M < A[P]:
            continue
        else:
            affords = M * V - M - M * P
            if affords <= 0:
                result += 1
                continue
            
            affords -= sum([min(A[n] + M - A[p], M) for p in range(P, n)])
            affords -= (N-n-1) * M
            
            if affords <= 0:
                result += 1
                continue
    print(result)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    V = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, V, P, A)

# Fixed code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, V: int, P: int, A: "List[int]"):
    P -= 1
    A = sorted(A, reverse=True)

    result = 0

    cumsum = [0 for i in range(N+1)]
    for n in range(N-1):
        cumsum[n+1] = A[n] + cumsum[n]

    for n in range(N):
        if n < P:
            result += 1
        elif A[n] + M < A[P]:
            continue
        else:
            affords = M * V - M - M * (P-1)
            if affords <= 0:
                result += 1
                continue
            
            sunmmation = A[n] * (n-P) + M * (n-P) - (cumsum[n] - cumsum[P])
            affords -= sunmmation
            affords -= (N-n) * M

            if affords <= 0:
                result += 1
                continue
    print(result)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    V = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, V, P, A)

if __name__ == '__main__':
    main()
# Buggy code:
N, M, V, P = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True) + [-10 ** 10]
L, R, sA, lP = 0, N, [A[P - 1]], A[P - 1]
for i in range(P, N):
    sA.append(sA[-1] + A[i])

while R - L > 1:
    mid = L + (R - L) // 2
    if mid < P:
        L = mid
    elif A[mid] + M <= A[P - 1]:
        R = mid
    else:
        mi = mid - P + 1
        if M * (N - mi) + (A[mid] + M - 1) * (mi + 1) - sA[mi] >= M * V:
            L = mid
        else:
            R = mid
print(L + 1)


# Fixed code:
N, M, V, P = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True) + [-10 ** 10]
L, R, sA, lP = 0, N, [A[P - 1]], A[P - 1]
for i in range(P, N):
    sA.append(sA[-1] + A[i])

while R - L > 1:
    mid = L + (R - L) // 2
    if mid < P:
        L = mid
    elif A[mid] + M < lP:
        R = mid
    else:
        mi = mid - P + 1
        if M * (N - mi) + (A[mid] + M) * mi - sA[mi - 1] >= M * V:
            L = mid
        else:
            R = mid
print(L + 1)
# Buggy code:
A = list(map(int, input().split()))

A.sort()
sumtab = [0] * (N + 1)
tmp_tab = 0
for i, Ai in enumerate(A):
    tmp_tab += Ai
    sumtab[i + 1] = tmp_tab

l = 0
r = N
while True:
    i = l + (r - l) // 2
    # print("#", l, r, i)
    #
    B = list(A)
    # everyone vote: i
    score_i = A[i] + M
    B[i] += M
    M_tmp = M * (V - 1)
    #
    rslt = False
    # print("#", i, B)
    for j in list(range(N))[::-1]:
        # print("##", j, M_tmp, B)
        if j == i:
            continue # me
        elif j > N - P:
            # make stronger problems stronger as possible
            tmp = min(M, M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        else:
            # make weaker problems weaker as possible
            if A[j] + M <= score_i:
                tmp = min(M, M_tmp)
            else:
                tmp = min(score_i - A[j], M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        #
        if M_tmp <= 0: break
    #
    # print("##", 'e', M_tmp, B)
    if M_tmp <= 0 and score_i >= B[N - P]:
        r = i
    else:
        l = i + 1
    #
    if l >= r: break
        
print(N - l)

# Fixed code:
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
sumtab = [0] * (N + 1)
tmp_tab = 0
for i, Ai in enumerate(A):
    tmp_tab += Ai
    sumtab[i + 1] = tmp_tab

l = 0
r = N
while True:
    i = l + (r - l) // 2
    # print("#", l, r, i)
    #
    B = list(A)
    # everyone vote: i
    score_i = A[i] + M
    B[i] += M
    M_tmp = M * (V - 1)
    #
    rslt = False
    # print("#", i, B)
    for j in list(range(N))[::-1]:
        # print("##", j, M_tmp, B)
        if j == i:
            continue # me
        elif j > N - P:
            # make stronger problems stronger as possible
            tmp = min(M, M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        else:
            # make weaker problems weaker as possible
            if A[j] > score_i:
                break
            if A[j] + M <= score_i:
                tmp = min(M, M_tmp)
            else:
                tmp = min(score_i - A[j], M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        #
        if M_tmp <= 0: break
    #
    # print("##", 'e', M_tmp, B)
    if i >= N - P:
        r = i
    elif M_tmp <= 0 and score_i >= B[N - P]:
        r = i
    else:
        l = i + 1
    #
    if l >= r: break
        
print(N - l)
# Buggy code:
n, m, v, p = [int(_) for _ in input().split()]
l = [int(_) for _ in input().split()]

l = sorted(l, reverse=True)

# print(l)

s = [0]

for i in range(1, n+1):
    s.append(s[-1] + l[-i])
s = sorted(s, reverse=True)

# print(s)

for i in range(p, n):
    x = (l[i] + m) * (i - p + 1) - (s[p - 1] - s[i])
    # print('i',i)
    # print('(l[i] + m)', (l[i] + m))
    # print('(i - p + 1)', (i - p + 1))
    # print('(s[p - 1] - s[i])', (s[p - 1] - s[i]))
    # print('x',x)
    y = 0
    if v >= (n - i) + (p - 1):
        y = v - (n - i) - (p - 1)

    # print('y * m', y * m)

    if x < y * m:
        ans = i
        break
print('ans', ans)


# Fixed code:
n, m, v, p = [int(_) for _ in input().split()]
l = [int(_) for _ in input().split()]

l = sorted(l, reverse=True)

# print(l)

s = [0]


for i in range(1, n+1):
    s.append(s[-1] + l[-i])
s = sorted(s, reverse=True)

# print(s)

for i in range(p, n):
    if l[i] + m < l[p - 1]:
        ans = i
        break
    x = (l[i] + m) * (i - p + 1) - (s[p - 1] - s[i])
    # print('i',i)
    # print('(l[i] + m)', (l[i] + m))
    # print('(i - p + 1)', (i - p + 1))
    # print('(s[p - 1] - s[i])', (s[p - 1] - s[i]))
    # print('x',x)
    y = 0
    if v >= (n - i) + (p - 1):
        y = v - (n - i) - (p - 1)

    # print('y * m', y * m)

    if x < y * m:
        ans = i
        break

    if i == n-1:
        ans = n

print(ans)
# Buggy code:
N,M,V,P=map(int,input().split())
import numpy as np
A=np.array(sorted(map(int,input().split())))
ng,ok=-1,N-P+1
while ng+1<ok:
    t=(ng+ok)//2
    if A[t]<A[-P] or np.sum(np.minimum(M,A[t]+M-A[t+1:-P+1]))<M*(V-P-t):
        ng=t
    else:
        ok=t
print(N-ok)

# Fixed code:
N,M,V,P=map(int,input().split())
import numpy as np
A=np.array(sorted(map(int,input().split())))
ng,ok=-1,N-P+1
while ng+1<ok:
    t=(ng+ok)//2
    if A[t]+M<A[-P] or np.sum(np.minimum(M,A[t]+M-A[t+1:N-P+1]))<M*(V-P-t):
        ng=t
    else:
        ok=t
print(N-ok)
# Buggy code:
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

def isOk(i):
    x = A[i] + M
    B = [x - a for a in A[i + 1:-(P - 1)]]
    if not B:
        return True
    K = V - i
    return min(B) >= 0 and sum(B) <= K * M

ok = N
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(N - ok)


# Fixed code:
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

def isOk(i):
    x = A[i] + M
    B = [x - a for a in A[max(0, P - 1): i]]

    if not B:
        return True
    cnt = sum(B) + (P - 1) * M + (N - i) * M
    return min(B) >= 0 and cnt >= M * V

ok = 0
ng = N
while ng - ok > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid
print(ng)
# Buggy code:
N,M,V,P=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)[::-1]
P-=1
def f(x):
  if x<=P:
    return True
  elif A[x]+M<A[P]:
    return False
  c=0
  for i in range(N):
    c+=min(M,A[x]+M-A[i])
  return c>=M*V

l,r=0,N
while l+1!=r:
  m=(l+r)//2
  if f(m):
    l=m
  else:
    r=m
print(l+1)
      

# Fixed code:
N,M,V,P=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)[::-1]
P-=1
def f(x):
  if x<=P:
    return True
  elif A[x]+M<A[P]:
    return False
  c=0
  for i in range(N):
    if i<P or i>=x+1:
      c+=M
    else:
      c+=A[x]+M-A[i]
  return c>=M*V

l,r=0,N
while l+1!=r:
  m=(l+r)//2
  if f(m):
    l=m
  else:
    r=m
print(l+1)
# Buggy code:
def main():
    import sys 
    input= sys.stdin.readline
    n,m,v,p=map(int,input().split())
    a=list(map(int,input().split()))
    a.sort(reverse=True)
    cnt=p
    #from bisect import bisect_left
    #print(a[5]+m)
    for i in range(p,n):
        if (a[i]+m )<a[p-1]:
            break
        # 3 2 2 1 1 0
        cnt+= ((a[i]+m)*(i-p+1)-sum(a[p-1:i])+(n-(i-p+1))*m)>=v*m:
              
    print(cnt)

if __name__=='__main__':
    main()

# Fixed code:
def main():
    import sys 
    input= sys.stdin.readline
    n,m,v,p=map(int,input().split())
    a=list(map(int,input().split()))
    a.sort(reverse=True)
    cnt=p
    #from bisect import bisect_left
    #print(a[5]+m)
    s=sum(a[p-1:p])
    for i in range(p,n):
        if (a[i]+m )<a[p-1]:
            break
        # 3 2 2 1 1 0
        
        cnt+= ((a[i]+m)*(i-p+1)-s+(n-(i-p+1))*m)>=v*m
        try: s+=a[i]
        except: continue      
    print(cnt)

if __name__=='__main__':
    main()
# Buggy code:
N,M,V,P=map(int,input().split())
B = sorted(list(map(int, input().split())))[::-1]
count=P
dif=0
for i in range(P,N):
    dif=+B[i-1]
    if V<=(P-1)+(N-i) and B[P-1]<=B[i]+M:
        count+=1
    elif M*(V-((P-1)+(N-i)))+dif<=(B[i]+M)*(i-P+1):
        count+=1
print(count)

# Fixed code:
N,M,V,P=map(int,input().split())
B = sorted(list(map(int, input().split())))[::-1]
count=P
dif=0
for i in range(P,N):
    dif+=B[i-1]
    if V<=(P-1)+(N-i) and B[P-1]<=B[i]+M:
        count+=1
    elif dif-B[i]*(i-P+1)<=M*(N-V) and B[P-1]<=B[i]+M:
        count+=1
print(count)
# Buggy code:
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
     
def is_ok(i):
  if i<0: return False
  cur,rival = A[i]+M, A[N-P]
  if cur < rival: return False
  rem_p = V - P - i
  if rem_p <= 0: return True
  j = 0
  for k in range(i+1,N-P+1):
    z = min(M, cur-A[k])
    j += z
    if j >= rem_p * M: return True
    return False
     
ok = N-P
ng = -1
while ok-ng > 1:
  m = (ok+ng)//2
  if is_ok(m):
    ok = m
    else:
      ng = m
     
print(N-ok)

# Fixed code:

N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

def is_ok(i):
    if i<0: return False
    cur,rival = A[i]+M, A[N-P]
    if cur < rival: return False
    rem_p = V - P - i
    if rem_p <= 0: return True
    j = 0
    for k in range(i+1,N-P+1):
        z = min(M, cur-A[k])
        j += z
        if j >= rem_p * M: return True
    return False

ok = N-P
ng = -1
while ok-ng > 1:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m

print(N-ok)
# Buggy code:
n,m,v,p = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
ans = 0
trash = 0
print(lis)
for i in range(n):
    if i+1 <= p:
        ans += 1
    else:
        if lis[i] + m >= lis[p-1]:
            if (lis[i]+m)*(i-(p-1))-trash >= m * (v-(p-1)-(n-i)):
  #                 print(lis[i]+m,i-(p-1)-trash,m*(v-(p-1)-(n-i)))
                ans += 1
    if i+1 >= p:
        trash += lis[i]
print(ans)


# Fixed code:
n,m,v,p = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
ans = 0
trash = 0
for i in range(n):
    if i+1 <= p:
        ans += 1
    else:
        if lis[i] + m >= lis[p-1]:
            if (lis[i]+m)*(i-(p-1))-trash >= m * (v-(p-1)-(n-i)):
  #                 print(lis[i]+m,i-(p-1)-trash,m*(v-(p-1)-(n-i)))
                ans += 1
    if i+1 >= p:
        trash += lis[i]
print(ans)
# Buggy code:
from collections import Counter
import numpy as np
import bisect
N,M,V,P = (int(x) for x in input().split())
A = list(map(int, input().split()))
dtype = [('points','int64'),('number','int64')]
c = np.array([x for x in Counter(A).items()],dtype=dtype)
c.sort(order='points')
value = [c[-i][1] for i in range(1,len(c)+1)]
cs = np.cumsum(value)
bs = bisect.bisect_left(cs,P)
thr = c[-bs-1][0]
limit = np.cumsum([(thr-c[i][0])*c[i][1] for i in range(len(c)-bs-1)])
broke = False
if bs == len(cs) - 1:
    print(N)
else:
    for i in range(len(cs)-bs-1):
        point = c[-bs-2-i][0]
        points_needed = thr - point
        if points_needed > M:
            print(cs[bs+i])
            broke = True
            break
        else:
            questions_raised = V - (N - cs[bs+i])
            if questions_raised >= P:
                points_overflowed = M * (questions_raised-(P-1))
                points_limit = limit[-1] - limit[-1-i] + (point+M-thr) * (cs[bs+i]-cs[bs-1])
                print(points_overflowed)
                print(points_limit)
                if points_overflowed > points_limit:
                    print(cs[bs+i])
                    broke = True
                    break
    if broke == False:
        print(N)

# Fixed code:
from collections import Counter
import numpy as np
import bisect
N,M,V,P = (int(x) for x in input().split())
A = list(map(int, input().split()))
dtype = [('points','int64'),('number','int64')]
c = np.array([x for x in Counter(A).items()],dtype=dtype)
c.sort(order='points')
value = [c[-i][1] for i in range(1,len(c)+1)]
cs = np.cumsum(value)
bs = bisect.bisect_left(cs,P)
thr = c[-bs-1][0]
limit = np.cumsum([(thr-c[i][0])*c[i][1] for i in range(len(c)-bs-1)])
broke = False
if bs == len(cs) - 1:
    print(N)
else:
    for i in range(len(cs)-bs-1):
        point = c[-bs-2-i][0]
        points_needed = thr - point
        if points_needed > M:
            print(cs[bs+i])
            broke = True
            break
        else:
            questions_raised = V - (N - cs[bs+i])
            if questions_raised >= P:
                points_overflowed = M * (questions_raised-(P-1))
                points_limit = limit[-1] - limit[-1-i] + (point+M-thr) * (cs[bs+i]-P+1)
                if points_overflowed > points_limit:
                    print(cs[bs+i])
                    broke = True
                    break
    if broke == False:
        print(N)
# Buggy code:
def check(n):
    x = A[n] + M
    B = A[:n] + A[n+1:-(P-1)]
    scores = M * (V - P)
    if x < B[-1]:
        return False
    for b in B:
        if b + M <= x:
            scores -= M
        else:
            scores -= x - b
        if scores <= 0:
            return True
    return False


N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
print(A)
left = 0
right = N - P
while left < right:
    mid = (left+right) // 2
    if check(mid):
        right = mid
    else:
        left = mid + 1
print(N - left)


# Fixed code:
def check(n):
    x = A[n] + M
    if P == 1:
        B = A[:n] + A[n+1:]
    else:
        B = A[:n] + A[n+1:-(P-1)]
    scores = M * (V - P)
    if x < B[-1]:
        return False
    for b in B:
        if b + M <= x:
            scores -= M
        else:
            scores -= x - b
        if scores <= 0:
            return True
    return False


N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

left = 0
right = N - P
while left < right:
    mid = (left+right) // 2
    if check(mid):
        right = mid
    else:
        left = mid + 1
print(N - left)
# Buggy code:
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, m, v, p = MAP()
a = LIST()
a = sorted(a, reverse=True)

def hantei(i):
    if i < p: return True
    if a[p-1] > a[i] + m: return False
    if ((i-p+1)*(a[i]+m)-sum(a[p-1:i]))+m*(p-1+n-i) < m*v: return False
    return True

def check(x):
    if (n-x)<=p:
        return True
 
    x_score = a[x]+m
    total_v = (v-x-p)*m
 
    if(a[n-p]>x_score):
        return False
 
    for i in range(x+1,n-p+1):
        total_v -= min(m,(x_score -a[i]))
    if total_v <= 0:
        return True
    else:
        return False

right = n-1
left = 0

while right-left > 1:
    mid = (right+left)//2
    if check(mid):
        left = mid
    else:
        right = mid

print(right)


# Fixed code:
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, m, v, p = MAP()
a = LIST()
a = sorted(a, reverse=True)

def hantei(i):
    if i < p: return True
    if a[p-1] > a[i] + m: return False
    if ((i-p+1)*(a[i]+m)-sum(a[p-1:i]))+m*(p-1+n-i) < m*v: return False
    return True

def check(x):
    if (n-x)<=p:
        return True
 
    x_score = a[x]+m
    total_v = (v-x-p)*m
 
    if(a[n-p]>x_score):
        return False
 
    for i in range(x+1,n-p+1):
        total_v -= min(m,(x_score -a[i]))
    if total_v <= 0:
        return True
    else:
        return False

if hantei(n-1):
    print(n)
    sys.exit()
right = n-1
left = 0

while right-left > 1:
    mid = (right+left)//2
    if hantei(mid):
        left = mid
    else:
        right = mid

print(right)
# Buggy code:
N, M, V, P = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)


ans = P
S = A[P-1]
for i in range(P, N):
    if V <= P-1+N-i:
        if A[i]+M >= A[P-1]:
            ans += 1
    else:
        if S+M*(V-P+1-N+i)/(i-(P-1)) <= (A[i]+M):
            ans += 1
    S += A[i]
print(ans)


# Fixed code:
N, M, V, P = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)


ans = P
S = A[P-1]
for i in range(P, N):
    if A[i]+M < A[P-1]:
        continue
    if V <= P-1+N-i:
        if A[i]+M >= A[P-1]:
            ans += 1
    else:
        if S+M*(V-P+1-N+i) <= (A[i]+M)*(i-(P-1)):
            ans += 1
    S += A[i]
print(ans)
# Buggy code:
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
S = sum(A)
for i in range(P-1):
    x = A.pop()
    S -= x
total_score = M*(V-P+1)
kazu = N - P + 1
for i in range(N-P+1):
    a = A.pop(0)
    total_score -= M
    S -= a
    kazu -= 1
    T = (M+a)*kazu - S
    if (a+M) > A[-1]:
        if T >= total_score:
            ans = kazu + P
            break
print(ans)

# Fixed code:
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
S = sum(A)
for i in range(P-1):
    x = A.pop()
    S -= x
total_score = M*(V-P+1)
kazu = N - P + 1
for i in range(N-P+1):
    a = A.pop(0)
    total_score -= M
    S -= a
    kazu -= 1
    T = (M+a)*kazu - S
    if i == N - P:
        ans = P
    else:
        if (a+M) >= A[-1]:
            if T >= total_score:
                ans = kazu + P
                break
print(ans)
# Buggy code:
#!/usr/bin/env python3
from itertools import accumulate

n, m, v, p = map(int, input().split())
a = sorted(map(int, input().split()))
cs = [0] + list(accumulate(a))
ans = p
rv = n - v
rp = n - p
for i in range(rp):
    l = rp - i
    if l >= rv and (cs[rp + 1] - cs[i + 1]) + (l - rv) * m <= (a[i] + m) * l:
        ans += 1
print(ans)


# Fixed code:
#!/usr/bin/env python3
from itertools import accumulate

n, m, v, p = map(int, input().split())
a = sorted(map(int, input().split()))
cs = [0] + list(accumulate(a))
ans = p
rv = n - v
rp = n - p
for i in range(rp):
    if a[i] + m < a[rp]:
        continue
    l = rp - i
    if (cs[rp + 1] - cs[i + 1]) + (l - rv) * m <= (a[i] + m) * l:
        ans += 1
print(ans)
# Buggy code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m,v,p = LI()
a = LI()
a.sort(reverse=True)
a = a[p-1:]
l = list(accumulate(a))
ans = p

for i in range(n-p):
    s = (n-p-(i+1))*m + p*m
    s += (a[i] + m) * i
    s -= (l[i] - a[i])
    if s >= m*v:
        ans += 1
print(ans)


# Fixed code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m,v,p = LI()
a = LI()
a.sort(reverse=True)
x = a[p-1]
a = a[p-1:]
l = list(accumulate(a))
ans = p

for i in range(n-p):
    if a[i+1] + m < x:
        continue
    s = (n-(p+i+1))*m + p*m
    s += (a[i+1] + m) * (i+1)
    s -= l[i]
    if s >= m*v:
        ans += 1
print(ans)
# Buggy code:
n=int(input())
a=map(int,input().split())
i=1
for k in a:
  if k==i: i+=1
1-=1
print(N-i if i>0 else -1)

# Fixed code:
n=int(input())
a=map(int,input().split())

j=1
k=0
for i in a:
  if i==j:
    k+=1
    j+=1

if k>0:
  print(n-k)
else: print(-1)
# Buggy code:
n = int(input())
a = list(map(int, input().split()))


if a == [i for i in range(1, n+1)]:
    print(0)
    
else:
    b = 0
    number = 1
    for i in range(n):
        if a[i] == number:
            number += 1
        else:
            b += 1
    if b == (number - 1):
        print(b)
    else:
        print(-1)    

# Fixed code:
n = int(input())
a = list(map(int, input().split()))


if a == [i for i in range(1, n+1)]:
    print(0)
    
else:
    b = 0
    number = 1
    for i in range(n):
        if a[i] == number:
            number += 1
        else:
            b += 1
    if number == 1:
        print(-1)
    elif b == (n - number + 1):
        print(b)
    else:
        print(-1)
# Buggy code:
n = int(input())
lst = list(map(int, intput().split()))
x = 0
for i in lst:
  if i == x + 1:
    	x = x + 1

print(n-x)


# Fixed code:
n = int(input())
lst = list(map(int, input().split()))
x = 0
for i in lst:
  if i == x + 1:
    	x = x + 1
if x == 0:
  print(-1)
else:
  print(n-x)