Problem: Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.  Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Submission attempts (in order):
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)
        index_left=None
        index_right=None
        if index!=0:
            index_left=index-1
        if index!=n:
            index_right=index+1
        value_left=x-1
        value_right=x+1
        
        for i in range(n):
            if index_left is not None:
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                if index_left!=0:
                    index_left=index_left-1
            elif index_right is not None:
                if num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_right!=n-1:
                    index_right=index_right+1
            value_left=value_left-1
            value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x>50:
        ans=101
    if x<=50:
        ans=0

print(ans)

num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n-1:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n-1:
            if num_list[index-1]==x-1:
                ans=x+1
            else:
                ans=x-1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        index_left=0
        index_right=n
        if index_left!=0:
            index_left=index-1
        if index_right!=n:
            index_right=index+1
        
        if index_left==0:
            ans=x-1
        elif index_right==n:
            if num_list[index_right-1]!=x-1:
                ans=x+1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n-1:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n-1:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n-1:
            if num_list[index-1]==x-1:
                ans=x+1
            else:
                ans=x-1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted