Language: C++

#include<bits/stdc++.h>
/**CLICK ss---> ctrl+j**/
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
void solve()
{
    int n, m, i, j, k, l;
    cin>>n>>m;
    /*if(m==0)
    {
        cout<<n<<endl;
        return;
    }*/
    int a[n+2];
    for(i=0; i<n; i++)
    {
        int x;
        cin>>x;
        a[x]=1;
    }
    /*sort(a,a+m);
    /*vector<int>vec, vec1;
    for(i=0; i<m; i++)
    {
        if(a[i]<n)
            vec.push_back(a[i]);
        else if(a[i]>n)
            vec1.push_back(a[i]);
    }
    ll p=0, pp=0;
    /*for(i=0; i<m; i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
    for(i=0; i<vec.size(); i++)
        cout<<vec[i]<<" ";
    cout<<endl;
    for(i=0; i<vec1.size(); i++)
    {
        cout<<vec1[i]<<" ";
    }
    cout<<endl;
    for(i=n-1; ; i--)
    {
        ll x=i;
        bool ok=true;
        for(j=0; j<vec.size(); j++)
        {
            if(vec[j]==x)
            {
                ok=false;
                break;
            }
        }
        if(ok==true)
        {
            p=x;
            break;
        }
    }
    for(i=n+1; ; i++)
    {
        ll x=i;
        bool ok=true;
        for(j=0; j<vec1.size(); j++)
        {
            if(vec1[j]==x)
            {
                ok=false;
                break;
            }
        }
        if(ok==true)
        {
            pp=x;
            break;
        }
    }
    if(p<0)
    {
        cout<<pp<<endl;
        return;
    }
    ll dif=abs(n-p);
    ll dif1=abs(n-pp);
    if(dif<dif1)
        cout<<p<<endl;
    else if(dif>dif1)
        cout<<pp<<endl;
   else
    cout<<min(p,pp)<<endl;
    ll pos=-1;
   for(i=0; i<m; i++)
   {
       if(a[i]==n)
       {
           pos=i;
           break;
       }
   }
   if(pos==-1)
   {
       for(i=0; i<m; i++)
       {
           if(a[i]>n)
           {
               pos=i-1;
               break;
           }
       }
   }
   ll p1=0;
   for(i=n-1; ;i--)
   {
       ll x=i;
       bool ok=true;
       for(j=pos; j>=0; j--)
       {
           if(a[j]==x)
           {
               ok=false;
               break;
           }
       }
       if(ok==true)
       {
           p1=x;
           break;
       }
   }
   
   
   
   ll pos1=-1;
   for(i=0; i<m; i++)
   {
       if(a[i]==n)
       {
           pos1=i;
           break;
       }
   }
   if(pos1==-1)
   {
       for(i=0; i<m; i++)
       {
           if(a[i]>n)
           {
               pos1=i-1;
               break;
           }
       }
   }
   ll p1=0;
   for(i=n-1; ;i--)
   {
       ll x=i;
       bool ok=true;
       for(j=pos; j>=0; j--)
       {
           if(a[j]==x)
           {
               ok=false;
               break;
           }
       }
       if(ok==true)
       {
           p1=x;
           break;
       }
   }*/
   
   int minn=110, now=110;
   for(int i=105 ; i>=0; i--)
   {
       if(!a[i] && (fabs(i-x)<minn || fabs(i-x)==minn && i<now))
       {
           minn=fabs(i-x);
           now=i;
       }
   }
   cout<<now<<endl;
}
int main()
{
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:183:28: error: 'x' was not declared in this scope
  183 |        if(!a[i] && (fabs(i-x)<minn || fabs(i-x)==minn && i<now))
      |                            ^