TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
n,a,b=map(int,input().split())
d=b-a
if d%2:print(-(-d//2))
else:
    print(min(n-b,a-1)+1+(d-1)//2)

a,s,d=map(int,input().split())
print(-(-s-d)//2)

n,a,b=map(int,input().split())
if b<a:b,a=a,b
ans=float("inf")
if abs(a-b)%2==0:print(abs(a-b)//2)

else:
    print(min(n-b+1,a)+abs(b-a-1)//2)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
n, a, b = map(int, input().split())
if (a+b) % 2 == 1:
  if a+b < 1+n:
    a = 1 - a
  else:
    a = 2 * n + 1 - a
print((a-b)/2 if a > b else (b-a)/2)


from decimal import Decimal
n, a, b = map(Decimal, input().split())
if (a+b) % 2 == 1:
  if a+b < 1+n:
    a = 1 - a
  else:
    a = 2 * n + 1 - a
print(abs((a-b)/2))


Verdicts: Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
n, a, b = [int(i) for i in input().split()]
a_distance = a-1
b_distance = n-b
ab_distance = b - a

if ab_distance % 2 == 0:
  result = ab_distance/2
  print("A")
elif ab_distance % 2 == 1:
  if a_distance < b_distance:
    result = a_distance + (ab_distance-1)/2 + 1
    print("B")
  else:
    result = b_distance + (ab_distance-1)/2 + 1
    print("C")
print(int(result))



n, a, b = [int(i) for i in input().split()]
a_distance = a-1
b_distance = n-b
ab_distance = b - a

if ab_distance % 2 == 0:
  result = ab_distance//2
else:
  if a_distance < b_distance:
    result = a_distance + (ab_distance-1)//2 + 1
  else:
    result = b_distance + (ab_distance-1)//2 + 1
print(result)



Verdicts: Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
N, A, B = (int(i) for i in input().split())

if (B - A) % 2 == 0:
    ans = (B - A) / 2
else:
    ans = min(A-1, N-B) + 1
    ans += (B - A -1) / 2
    
print(ans)

N, A, B = (int(i) for i in input().split())

def f(A, B):
  return (B - A) // 2

if (B - A) % 2 == 0:
    ans = f(A, B)
else:
    
    ans_a = A + f(1, B - A)
    
    ans_b = (N - B + 1) + f(A + N - B +1, N)
    # 
    
    ans = min(ans_a, ans_b)
    
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
n, a, b = list(map(int, input().split()))
k = b - a
if k % 2 == 1:
    print(min(a-1, n-b)+1+(z-1)//2)
else:
    print(z//2)


n, a, b = list(map(int, input().split()))
k = b - a
if k % 2 == 1:
    print(min(a-1, n-b)+1+(k-1)//2)
else:
    print(k//2)


Verdicts: Runtime Error

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
n,a,b = list(map(int,input().split()))
if (b-a)%2==1:
    if a-1 > n-b:
        q=n-b+1
        z=n-q
        print((q+z)/2)
    else:
        z=b-a
        print((z-1)/2)

n,a,b = list(map(int,input().split()))
if (b-a)%2==1:
    if a-1 > n-b:
        q=n-b+1
        z=n-q
        print((q+z)/2
    else:
        z=b-a
        print((z-1)/2)

n,a,b = list(map(int,input().split()))
z=b-a
if z%2==1:
    print(min(a-1,n-b)+1+(z-1)//2)
else:
    print(z//2)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
n, a, b = map(int, input().split())

if (b - a) % 2:
  print((b - a) % 2)
else:
  print(min(a - 1, n - b,) + 1 + (b - a - 1) // 2)

n, a, b = map(int, input().split())

if (b - a) % 2:
  print((b - a) // 2)
else:
  print(min(a - 1, n - b,) + 1 + (b - a - 1) // 2)


n, a, b = map(int, input().split())

if (b - a) % 2 == 0:
  print((b - a) // 2)
else:
  print(min(a - 1, n - b,) + 1 + (b - a - 1) // 2)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
N, A, B = map(int, input().split())
if not B - A % 2:
    print((B - A)/2)
else:
    if B - 1 < 5 - A:
        print(B-1)
    else:
        print(5-A)

N, A, B = map(int, input().split())
if not (B - A) % 2:
    print((B - A)//2)
else:
    if B - 1 > N - A:
        b = N - A + 1
        a = N - B + 1
        A = a
        B = b

    if B-A == 1:
        print(B-1)

    else:
        print(-(-(B-A)//2) + A - 1)

Verdicts: Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
N,A,B = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B
sumAB = A + B
if sumN < sumAB:
    print(N2A)
else:
    print(B - 1)

N,A,B = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B 
sumAB = A + B 


if diff % 2 == 0:
    print(diff // 2)
else:
    if N2B < A - 1:
        tmp = (N - (A + N2B))//2 + N2B
        if (N - (A + N2B))%2 == 1:
            tmp = tmp + 1
        if N2A < tmp:
            print(N2A)
        else:
            print(tmp)
    else:
        tmp = ((B + 1 - A) - 1)//2 + A - 1
        if ((B + 1 - A) - 1)%2 == 1:
            tmp = tmp + 1
        if B-1 < tmp: 
            print(B - 1)
        else:
            print(tmp)

Verdicts: Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
n, a, b = map(int, input().split())

if (a - b) % 2 == 0:
    print((a - b)//2)
    exit()

if a > b:
    a, b = b, a

print(min(a + (b-a-1)//2, n - b + 1 + (n - (a + (n - b + 1)))//2))

n, a, b = map(int, input().split())

if (a - b) % 2 == 0:
    print(abs((a - b)//2))
    exit()

if a > b:
    a, b = b, a

print(min(a + (b-a-1)//2, n - b + 1 + (n - (a + (n - b + 1)))//2))

Verdicts: Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
    N,A,B = map(int,input().split())
    if (B-A)%2==0:
        print(str(int(B-(B+A)/2)))
    else:
        if B-A==1:
            if N-A>B-1:
                print(B-1)
            else:
                print(N-A)
        else:
            if N-A>B-1:
                print(A+(A-B)/2)
            else:
                print(B+(B-A)/2)

N,A,B = map(int,input().split())
if (B-A)%2==0:
    print(str(int(B-(B+A)//2)))
else:
    if N-B>A-1:
        print(str(int(A+(B-A-1)//2)))
    else:
        print(str(int(N-B+1+(B-A-1)//2)))

Verdicts: Runtime Error

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

N, a, b = ints()
print(N, a, b)
d = b-a
if d%2==0:
  print(d//2)
else:
  print(min(b-1, N-a))



def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

def f(a, b):
  d = b-a
  if d%2==0:
    return d//2

  e = N-b
  g = a-1
  return min(e+1+f(a+e+1, N), g+1+f(1, b-g-1))

N, a, b = ints()
print(f(a, b))



Verdicts: Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
n, a, b = map(int,input().split())

if (b - a) % 2 ==0:
    print((b-a)/2)
else:
    print((b-a)/2 + 1)

n, a, b = map(int,input().split())

if (b - a) % 2 ==0:
    print((b-a)/2)
else:
    print(min(b-1,n-a))

n, a, b = map(int,input().split())

if (b - a) % 2 ==0:
    print((b-a)//2)
else:
    print(min(a-1,n-b)+1+(b-a)//2)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
import math
N, a, b = map(int, input().strip().split())

if (b-a)%2==0:
    ans=int(math.round((b-a)/2))
else:
    ans=min(a-1,N-b)+math.ceil((b-a)/2)
print(ans)

import math
N, a, b = map(int, input().strip().split())

if (b-a)%2==0:
    ans=int(math.raound((b-a)/2))
else:
    ans=min(a-1,N-b)+math.ceil((b-a)/2)
print(ans)

import math
N, a, b = map(int, input().strip().split())

if (b-a)%2==0:
    ans=(b-a)//2
else:
    ans=min(a-1,N-b)+1+(b-a)//2
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
def main():
    N, A, B = map(int, input().split())
    
    ans = 0

    while True:
        left_s = A - 1
        right_s = N - B
        sub = B - A
        
        if A == B:
            return ans
        ans+=1
        
        if sub % 2 == 0:
            return ans + (sub / 2)
        
        else:
            if left_s < right_s:
                if A != 1:
                    A -= 1
                B -= 1
            else:
                if B != N:
                    B += 1
                A += 1

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


def main():
    N, A, B = map(int, input().split())
    
    sub = B - A

    left_s = A - 1
    right_s = N - B
        
    
    if sub % 2 == 0:
        return sub / 2
    
    else:
        return (min(left_s, right_s) + 1 + ((sub - 1)/2))
    
if __name__ == '__main__':
    print(main())

def main():
    N, A, B = map(int, input().split())
    
    sub = B - A

    left_s = A - 1
    right_s = N - B
        
    
    if sub % 2 == 0:
        return sub // 2
    
    else:
        return (min(left_s, right_s) + 1 + ((sub - 1)//2))
    
if __name__ == '__main__':
    print(main())

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
N,A,B=[int(x) for x in input().split()]

if (B-A)%2==0:
    print((B-A)/2)

else:
    print(int(min(N-A,B-1)))


N,A,B=[int(x) for x in input().split()]

if (B-A)%2==0:
    print(int((B-A)//2))

else:
    if B-1 <= N-A:
        print(int(min((B-A-1)//2+A,B-1)))
    if B-1 > N-A:
        print(int(min(N-A, (N-(A+N-B+1))//2 + N-B+1)))


Verdicts: Wrong Answer

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
N,A,B = map(int,input().split())

if (B - A) % 2 == 0:
  print((B - A) // 2)
else:
  if 
  print(min(B - 1 , N - A))

N,A,B = map(int,input().split())

if (B - A) % 2 == 0:
  print((B - A) // 2)
else:
  NA = N - A
  B1 = B - 1
  if NA < B1:
    distance = N - B
    adjust = distance + 1
    moveA = A + adjust
    print(((N - moveA) // 2) + adjust)
  else:
    distance = A - 1
    adjust = distance + 1
    moveB = B - adjust
    print(((moveB - 1) // 2) + adjust)

Verdicts: Runtime Error

Accepted
Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):

N,A,B = list(map(int, input().split()))

if Lab%2==0:
    #case Lab is even
    ans = int(B-A/2)
else:
    #case Lab is odd
    ans = min(A-1,N-B) + 1 + int((B-A-1)/2)

print(ans)


N,A,B = list(map(int, input().split()))

if int((B-A)%2)==0:
    #case Lab is even
    ans = int(B-A/2)
else:
    #case Lab is odd
    ans = min(A-1,N-B) + 1 + int((B-A-1)/2)

print(ans)


N,A,B = list(map(int, input().split()))

Lab = B-A
La = A-1
Lb = N-B

if Lab%2==0:
    #case Lab is even
    ans = Lab/2
else:
    #case Lab is odd
    ans = min(La,Lb) + 1 + (Lab-1)/2
    
ans = int(ans)
ans


N,A,B = list(map(int, input().split()))

Lab = B-A
La = A-1
Lb = N-B

if Lab%2==0:
    #case Lab is even
    ans = Lab//2
else:
    #case Lab is odd
    ans = min(La,Lb) + 1 + (Lab-1)//2
    
print(ans)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
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())
a = sorted(list(map(int, input().split())), reverse=True)
ans = p
c = [0]
cnt = 0
for i in range(n):
  
  cnt += a[i]
  c.append(cnt)
  
from bisect import bisect_right
for i in range(p,n):
  h = a[i]+m
  x = bisect_right(a, h) 
  free = v - (x + (n-i)) 
  s = c[i+1] - c[x] 
  d = h * (i-x) - s 
  if d >= free*m and d >= 0 and free >= 0:
    ans += 1
print(ans)

n, m, v, p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = p
c = [0]
cnt = 0
for i in range(n):
  
  cnt += a[i]
  c.append(cnt)
  
from bisect import bisect_right
for i in range(p,n):
  h = a[i]+m
  free = v - (p-1) - (n-i)
  if free >= 0 and h >= a[p-1]:
    d = h * (i-p+1) - (c[i]-c[p-1]) 
    if d >= free*m:
      ans += 1
  else:
    if h >= a[p-1]:
      ans += 1
print(ans)

Verdicts: Wrong Answer

Accepted
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):
a = sorted(list(map(int, input().split())), reverse=True)


def isOK(x):
  x -= 1
  if a[x] + m < a[p-1]:
    return False
  elif x+1 <= p:
    return True
  else:
    pos = m * n
    for i in range(p-1,x):
      pos -= a[i] - a[x]
    if pos >= m * v:
      return True
    else:
      return False

def binary_search():
    ok = p-1
    ng = n
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if isOK(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = binary_search()  
print(ans)

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


def isOK(x):
  border = a[x-1]
  if border + m < a[p-1]:
    return False
  elif x <= p:
    return True
  else:
    margin = m * n
    for i in range(p-1,x-1):
      margin -= a[i] - border
    if margin >= m*v:
      return True
    else:
      return False

def binary_search():
    ok = p-1
    ng = n+1
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if isOK(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = binary_search()  
print(ans)

Verdicts: Runtime Error

Accepted
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):
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

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

ok = 0
ng = n
while ng - ok > 1:
    nw = (ok+ng) // 2
    if f(nw):
        ok = nw
    else:
        ng = nw
print(ng)


#!/usr/bin python3
# -*- coding: utf-8 -*-

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

def f(x):
    if x < p:
        return True
    else:
        res = m * v
        res -= m * (n-x)
        res -= m * (p-1)
        for i in range(p-1, x):
            res -= min(m, max(0,a[x]+m-a[i]))
        return res <= 0

ok = 0
ng = n
while ng - ok > 1:
    nw = (ok+ng) // 2
    if f(nw):
        ok = nw
    else:
        ng = nw
print(ng)


#!/usr/bin python3
# -*- coding: utf-8 -*-

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

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

ok = 0
ng = n
while ng - ok > 1:
    nw = (ok+ng) // 2
    if f(nw):
        ok = nw
    else:
        ng = nw
print(ng)


Verdicts: Wrong Answer

Wrong Answer

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


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)


Verdicts: Runtime Error

Accepted
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())
a = list(map(int, input().split()))

a.sort()

b = [a[x] for x in range(n - p)]

total = sum(b)

vote=(v - p) * m

ans = p
if len(b) > 1:
    for n, i in enumerate(b):
        if (total - i + vote) // (len(b) - 1) <= i + m:
            ans += len(b) - n
            break

print(ans)

from math import ceil
n, m, v, p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)[p - 1:]
l = 0
r = n - p

while l != r:
    k = ceil((l + r) / 2)
    b = a[k] + m
    if b < a[0] or (v - (n - k)) * m > (k * b - sum(a[:k])):
        r = k - 1
    else:
        l = k
print(p+l)

Verdicts: Wrong Answer

Accepted
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())
A = list(map(int,input().split()))

A.sort(reverse = True)

def solve(n):
    if n < P:
        return True
    if A[n-1] > A[n] + M:
        return False
    
    cnt = M * (P - 1 + N - n)
    for i in range(P-1,n):
        cnt += max(0, A[n] + M - A[i])
    
    print(n, cnt)
    return cnt >= M * V

left = 0
right = N

while left + 1 < right:
    mid = (left + right) // 2
    if solve(mid):
        left = mid
    else:
        right = mid

print(right)

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

A.sort(reverse = True)

def solve(n):
    if n < P:
        return True
    if A[n-1] > A[n] + M:
        return False
    
    cnt = M * (P - 1 + N - n)
    for i in range(P-1,n):
        cnt += max(0, A[n] + M - A[i])
    
    return cnt >= M * V

left = 0
right = N

while left + 1 < right:
    mid = (left + right) // 2
    if solve(mid):
        left = mid
    else:
        right = mid

print(right)

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

A.sort(reverse = True)

def solve(n):
    
    if n < P:
        return True
    
    if A[P-1] > A[n] + M:
        return False
    
    cnt = M * (P - 1 + N - n)
    for i in range(P-1,n):
        cnt += max(0, A[n] + M - A[i])
    
    return cnt >= M * V

left = 0
right = N

while left + 1 < right:
    mid = (left + right) // 2
    if solve(mid):
        left = mid
    else:
        right = mid

print(right)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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

def f(i):
    if v<=p+n-2-i: return 1
    elif a[i]+m<a[p-1]: return 0
    able=(p+n-2-i)*m
    able+=sum([a[i]+m-a[k] for k in range(p-1,i)])
    if able>=m*v: return 1
    else: return 0

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

print(a)
print([f(i) for i in range(n)])
l,r=0,n-1
if f(r)==1: print(n);sys.exit()
while r-l>1:
    tmp=(l+r)//2
    if f(tmp)==1: l=tmp
    else: r=tmp
print(r)


import sys

def f(x):
    if v<=p+n-1-x: return 1
    elif a[x]+m<a[p-1]: return 0
    able=(p+n-1-x)*m
    able+=sum([a[x]+m-a[k] for k in range(p-1,x)])
    if able>=m*v: return 1
    else: return 0

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

l,r=0,n-1
if f(r)==1: print(n);sys.exit()
while r-l>0:
    if r-l==1 and f(l)==1 and f(r)==0: break
    tmp=(l+r)//2
    if f(tmp)==1: l=tmp
    else: r=tmp
print(l+1)

import sys

def f(x):
    if a[x]+m<a[p-1]: return 0
    elif v<=p+n-1-x: return 1
    able=(p+n-1-x)*m
    able+=sum([a[x]+m-a[k] for k in range(p-1,x)])
    if able>=m*v: return 1
    else: return 0

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

l,r=0,n-1
if f(r)==1: print(n);sys.exit()
while r-l>0:
    if r-l==1 and f(l)==1 and f(r)==0: break
    tmp=(l+r)//2
    if f(tmp)==1: l=tmp
    else: r=tmp
print(l+1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
p-=1

a.sort(reverse=True)

ans=0
s = sum(a)

def safe(index):
    if a[p]>a[index]+m:
        return False
    i=0
    while a[i]>=a[index]+m:
        i+=1
    if i>index:
        return True
    intg = 0
    i = max(i,p)
    while i<index:
        intg += a[index] + m - a[i]
        i+=1
    intg += (len(a)-1-index)*m
    print(intg,m*(v-1))
    return intg >= m*(v-1) - p*m

left = 0
right = len(a)-1
ans = int((right - left)/2)
if safe(right):
    ans = right
else:
    j = safe(ans)
    while not(j and not safe(ans+1)):
        if j:
            left = ans
        else:
            right = ans
        ans = left + int((right - left)/2)
        j = safe(ans)
print(ans+1)

for i in range(len(a)):
    print(a[i],safe(i))


n,m,v,p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
p-=1

a.sort(reverse=True)

ans=0
s = sum(a)

def safe(index):
    if a[p]>a[index]+m:
        return False
    i=0
    while a[i]>=a[index]+m:
        i+=1
    if i>index:
        return True
    intg = 0
    i = max(i,p)
    while i<index:
        intg += a[index] + m - a[i]
        i+=1
    intg += (len(a)-1-index)*m
    #print(intg,m*(v-1))
    return intg >= m*(v-1) - p*m

left = 0
right = len(a)-1
ans = int((right - left)/2)
if safe(right):
    ans = right
else:
    j = safe(ans)
    while not(j and not safe(ans+1)):
        if j:
            left = ans
        else:
            right = ans
        ans = left + int((right - left)/2)
        j = safe(ans)
print(ans+1)


Verdicts: Wrong Answer

Accepted
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())
import numpy as np
A = list(map(int,input().split()))
A = np.array(sorted(A,reverse=True))
ans = P
if N//2<=V:
  V = N-V
  A += M
  x = A[P-1]
  for i in range(P,N):
    a = A[i]
    if a==x:
      ans += 1
    else:
      y = i
      break
  
  for i in range(y,y+M):
    z = i
    a = A[i]
    if x-V<=a:
      ans+=1
    else:
      break

  for j in range(z+1,N):
    if a==A[j]:
      ans+=1
      
    else:
      break
  print(ans)
  
else:
  x = A[P-1]
  for i in range(P,N):
    a = A[i]
    if a==x:
      ans += 1
    else:
      y = i
      break
  for i in range(y,y+M):
    a = A[i]

N,M,V,P = map(int,input().split())
import numpy as np
A = list(map(int,input().split()))
A = np.array(sorted(A,reverse=True))
ans = P
x = A[P-1]
y = N
for i in range(P,N):
  a = A[i]
  if x==a:
    ans+=1
  else:
    y=i
    break

z = sum(A[P-1:y])
for i in range(y,N):
  a = A[i]
  d = a+M
  if x<=d:
    b = N-i+P-1
    c = M*(V-b)
    e = z+c
    f = d*(i-P+1)
    if f>=e:
      ans+=1
      
  z+=a
print(ans)

Verdicts: Runtime Error

Accepted
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())
A = list(map(int,input().split()))


A = sorted(A,reverse=True)

left=0
right=N-1

while left<=right:
    mid = (left+right)//2

    if mid<P:
        left = mid + 1
    elif A[mid] + M < A[P-1]:
        right = mid - 1
    else:
        voted = P * M
        for _ in range(mid+1,N):
            voted += M

        for v in A[P-1:mid]:
            voted += min(max(A[mid]+M-v,0),M)

        if voted <=M*V:
            right = mid-1
        else:
            left= mid+1

print(low)


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


A = sorted(A,reverse=True)

left=0
right=N-1

while left<=right:
    mid = (left+right)//2

    if mid<P:
        left = mid + 1
    elif A[mid] + M < A[P-1]:
        right = mid -1
    else:
        voted = P * M
        for _ in range(mid+1,N):
            voted += M

        for v in A[P-1:mid]:
            voted += A[mid]+M-v

        if voted >= M*V:
            left= mid+1
        else:
            right = mid-1

print(left)


Verdicts: Runtime Error

Accepted
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())
A = list(map(int, input().split()))
A.sort(reverse=True)
W = N - V

def isOk(n):
    if n < P:
        return True
    b = A[n]

    D = [max(0, a - b) for a in A][P - 1:][:: -1]
    cnt = 0
    diff = 0

    for left in range(0, len(D), W):
        T = D[-1]
        cnt += T
        cnt -= diff // W
        diff %= W
        for d in D[left: left + W]:
            diff += T - d

    return cnt <= M

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

print(ng)

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

ok = -1
ng = N


V = N - V
def isOk(n):
    b = A[n]
    cnt = [max(0, a - b) for a in A]
    cnt = cnt[P:]
    return sum(cnt) <= M * V

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

print(max(P, ng))

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
    cnt = i * M + (P - 1) * M
    for b in B:
        cnt += max(0, b)
    return min(B) >= 0 and cnt <= V * M

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

print(N - ok)


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

A.sort(reverse=True)

def isOk(i):
    if i < P:
        return True

    b = A[i] + M
    if b < A[P - 1]:
        return False

    cnt = (P - 1) * M + (N - i) * M

    for a in A[P - 1: i]:
        cnt += max(0, b - a)
    return cnt >= M * V

ok = 0
ng = N
while ng - ok > 1:
    mid = (ng + ok) // 2

    if isOk(mid):
        ok = mid
    else:
        ng = mid
print(ng)



Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted