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

import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,m,v,p = map(int,readline().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)

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)):
  
                ans += 1
    if i+1 >= p:
        trash += lis[i]
print(ans)


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)

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)

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

li = []

cnt = 1
now = 0
ans = 0

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



for i in range(n):
    if li[i] > p:
        ans += 1
    else:
        if lis[i] + m >= border:
            num = (p-1)+(n-li[i]-1)+1
            if num >= v:
                ans += 1
        else:
            ans += 1
print(ans)

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)

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)


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)

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)):
  
                ans += 1
    if i+1 >= p:
        trash += lis[i]
print(ans)


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted