Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
read = sys.stdin.buffer.read

n,m,v,p = map(int,input().split())
lis = np.array(read().split(),np.int64)



lis.sort()

def test(i):
    if n-i <= p:
        return True

    num = lis[i] + m
    li = np.zeros(n,np.int64)
    li = num-lis
    li = np.minimum(li,m)
    li[n-p+1:] = m
    if(li < 0).any():
        return False
    li[i] = 0
    x = li.sum()
    return li.sum() >= m * (v-1)

low = -1
high = n-1

while low +1 < high:
    mid = (low + high) // 2
    if test(mid):
        low = mid
    else:
        high = mid

ans = n-high

print(ans)


Fixed submission:
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 python submission (verdict: Runtime Error):
import numpy as np

n,m,v,p = map(int,input().split())
lis = list(map(int,input().split()))



lis.sort()

def test(i):
    if n-i <= p:
        return True
    
    num = lis[i] + m
    li = np.zeros(n,np.int64)
    li = num-lis
    li = np.minimum(li,m)
    li[n-p+1:] = m
    if(li < 0).any():
        return False
    li[i] = 0
    x = li.sum()
    return li.sum() >= m * (v-1)
    
low = -1
high = n-1

while low +1 < high:
    mid = (low + high) // 2
    if test(mid):
        low = mid
    else:
        high = mid

ans = n-high

print(ans)

Fixed submission:
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 python submission (verdict: Runtime Error):
n,m,v,p = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(reverse=True)

li = []

  # print(lis)
cnt = 1
now = 0
ans = 0

border = lis[p-1]
li.append(0)
ind = 0
for i in range(n-1):
    if lis[i]!=lis[i+1]:
        now += cnt
        cnt = 1
    else:
        cnt += 1
    if now <= p:
        ind += 1
    li.append(now)

  #print(li)
sa = 0
keykey = 1
key = 0

for i in range(n):
    if i >= p-1:
        sa += lis[i]
        if keykey:
            key = i
        keykey = 0

    if li[i]+1 <= p:
        ans += 1
  #        print(i,1)

    else:
        if lis[i] + m >= border:
            num = (p-1)+(n-li[i]-1)+1
            if num >= v:
                ans += 1
  #                print(i,2)
            else:
                nu = v-num
                if (sa -lis[i])-lis[i]*(i-key) <= (key-nu-1)*m:
                    ans += 1
  #                    print(i,3)
  #                    print(sa,lis[i],i,key,key-nu,m)
                else:
  #                    print(i,4)
  #                    print(sa, lis[i], i, key, key - nu, m)
  #        else:
  #            print(i,5)
    if i != n-1:
        if sa != 0 and lis[i] == lis[i+1]:
            sa -= lis[i]
print(ans)

Fixed submission:
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 python submission (verdict: Runtime Error):
n,m,v,p = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(reverse=True)

li = []

  # print(lis)
cnt = 1
now = 0
ans = 0

border = lis[p-1]
li.append(0)
ind = 0
for i in range(n-1):
    if lis[i]!=lis[i+1]:
        now += cnt
        cnt = 1
    else:
        cnt += 1
    if now <= p:
        ind += 1
    li.append(now)

print(li)
sa = 0
keykey = 1
key = 0

for i in range(n):
    if i >= p-1:
        sa += lis[i]
        if keykey:
            key = i
        keykey = 0

    if li[i]+1 <= p:
        ans += 1
   #       print(i,1)

    else:
        if lis[i] + m >= border:
            num = (p-1)+(n-li[i]-1)+1
            if num >= v:
                ans += 1
   #               print(i,2)
            else:
                nu = v-num
                if (sa -lis[i])-lis[i]*(i-key) <= (key-nu-1)*m:
                    ans += 1
   #                   print(i,3)
   #                   print(sa,lis[i],i,key,key-nu,m)
                else:
   #                   print(i,4)
  #        else:
  #            print(i,5)
print(ans)

Fixed submission:
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)