Problem: 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?

Submission attempts (in order):
import sys
import copy
import bisect
import numpy as np

def solve(a,n,N,M,V,P):
    if N-n+1 >= V:
        b = copy.deepcopy(a)
        b[n-1] += M
        tmp = b[n-1]
        b = sorted(b[0:n], reverse=True)
        k = bisect.bisect_left(b,tmp)
        if k<=P-1:
            return True
        else:
            return False
    else:
        V2 = V-N+n-1
        b = copy.deepcopy(a[0:n])
        b[n-1] += M
        tmp = b[n-1]
        b.sort()
        k = bisect.bisect_left(b,tmp)
        k = len(b)-k
        if k+N-1-n < V:
            if P<=k:
                return False
            elif P>=n:
                return True
            else:
                V2 = V-N+n-1
                num = P-k-N+n-1
                aaa = min([V2-1, num])
                if (np.sum(a[n-num:n])+M*aaa+num-1)//num <= tmp:
                    return True
                else:
                    return False
        else:
            b = copy.deepcopy(a)
            b[n-1] += M
            tmp = b[n-1]
            b = sorted(b[0:n])
            k = bisect.bisect_right(b,tmp)
            k = len(b)-k
            if k<=P:
                return True
            else:
                return False

def main():
    N,M,V,P = map(int,input().split())
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    lo = 0
    hi = 2*N
    while lo + 1 < hi:
        cnt = (lo + hi) // 2
        if solve(a,cnt,N,M,V,P):
            lo = cnt
        else:
            hi = cnt

    return hi

if __name__ == '__main__':
    ans = main()
    print(ans)


import bisect
N, M, V, P = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
eps = 0.1
def func(k):
    # print("tsrget:"+str(k))
    used = 0
    tmp = a[:k]+a[k+1:]
    val = a[k]+M
    x1 = N-1-bisect.bisect(tmp, val+eps)
    x2 = bisect.bisect(tmp, val-eps)
    x3 = N-(x1+x2+1)
    # print(tmp,val,x1,x2,x3)
    if x1 >= P:
        return False
    v = V - (x1+1)
    p = P - (x1+1)
    used += x1+1
    if v <= 0:
        return True
    
    
    if x3 >= p > 0:
        x3 -= p
        v -= p
        used += p
        p = 0
    if p>0:
        p -= x3
        v -= x3
        used += x3
    if x2 >= p > 0:
        x2 -= p
        v -= p
        used += p
        p = 0
    if p>0:
        p -= x2
        v -= x2
        used += x2
    if v <= 0:
        return True
    
    tmp2 = tmp[:N-used]
    rest = sum([min(M,val-val2) for val2 in tmp2])
    # print(tmp2,N,x1,x3,p,v, rest)
    if rest >= M*v:
        return True
    return False

ok = N-1  # exist
ng = -1  # not exist
while abs(ok - ng) > 1:
    cnt = (ok + ng) // 2
    t = func(cnt)
    # print(t)
    if t:
        ok = cnt
    else:
        ng = cnt
print(N-ok)

Verdicts: Runtime Error

Accepted