Official

B - Cutoff Editorial by en_translator


Use a loop to simulate the case where he gets from \(0\) points through \(100\) points, and the problem can be solved.

One can remove the smallest and largest scores and find the sum of the remaining as follows for example:

  • Sort the scores of the rounds in ascending order, and find the sum of all the elements except for the first and last.
  • Find the sum of all the rounds first, then subtract the largest and smallest scores from them.

We introduce sample code for both approaches.

Sample code (Python):

N,X = map(int,input().split())
A = list(map(int,input().split()))
A.append(-1)

for last in range(0,101):
    B = A.copy()
    B[N-1] = last
    B.sort()
    sum = 0
    for i in range(1,N-1):
        sum += B[i]
    if sum >= X:
        print(last)
        exit()

print("-1")

Sample code (Python):

N,X = map(int,input().split())
A = list(map(int,input().split()))
A.append(-1)

for last in range(0,101):
    B = A.copy()
    B[N-1] = last
    sum = 0
    ma = 0
    mi = 100
    for p in B:
        sum += p
        ma = max(ma,p)
        mi = min(mi,p)
    score = sum - ma - mi

    if score >= X:
        print(last)
        exit()
    
print("-1")

posted:
last update: