Language: C++

#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    
    int X,N;
    int answer=0;
    int dis=9999;
    bool match=false;
    cin>>X>>N;
    if(N==0){
      cout<<X<<endl;
      return 0;
    }
    vector<int> p(N);
    for(int i=0;i<N;i++)
    {
       cin>>p[i];
    }
    sort(p.begin(),p.end());
    //p.pop_back();
    //reverse(p.begin(),p.end());
    /*for(int i=0;i<N;i++)
    {
      cout<<p[i]<<endl;
    }*/
    for(int i=0;i<N-1;i++)
    {
      for(int t=p[i]+1;t<p[i+1];t++)
      {
        //cout<<"abs"<<abs(t-X)<<endl;
        if(abs(X-t)<dis){
          answer=t;
          dis=abs(X-t);
          match=true;
          //cout<<t<<endl;
        }
      }
    }
    if(match){
        cout<<answer<<endl;
    }
    else
    {
        if(max(p)>=100)cout<<p[N-1]+1<<endl;
        else if(min(p)<=1)cout<<p[0]-1<<endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:15: error: no matching function for call to 'max(std::vector<int>&)'
   51 |         if(max(p)>=100)cout<<p[N-1]+1<<endl;
      |            ~~~^~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
a.cc:51:15: note:   'std::vector<int>' is not derived from 'std::initializer_list<_Tp>'
   51 |         if(max(p)>=100)cout<<p[N-1]+1<<endl;
      |            ~~~^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided
a.cc:52:20: error: no matching function for call to 'min(std::vector<int>&)'
   52 |         else if(min(p)<=1)cout<<p[0]-1<<endl;
      |                 ~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
a.cc:52:20: note:   'std::vector<int>' is not derived from 'std::initializer_list<_Tp>'
   52 |         else if(min(p)<=1)cout<<p[0]-1<<endl;
      |                 ~~~^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided