Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TAHMID RAHMAN
- DAMIAN FOREVER
- MATH LOVER
- NEVER GIVE UP
- */
- #include<bits/stdc++.h>
- using namespace std;
- #define pi acos(-1.0)
- #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- #define ll long long
- #define pb push_back
- #define fi first
- #define se second
- #define in insert
- #define mp make_pair
- #define GCD(a,b) __gcd(a,b);
- #define endl "\n"
- #define FRU freopen("out.txt","w",stdout)
- #define FRO freopen("in.txt","r",stdin)
- #define INFLL 9223372036854775807
- #define debug 0
- #define MAXN 100001
- //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
- int main()
- {
- fastio;
- ll n,p,i,c=INFLL,x=-1,y=0,z=0;
- cin>>n>>p;
- vector<ll>v(p);
- set<ll>s;
- if(p==0)
- {
- cout<<n<<endl;
- return 0;
- }
- for(i=0;i<p;i++)
- {
- cin>>v[i];
- if(abs(n-v[i])<c)
- {
- c=abs(n-v[i]);
- x=v[i];
- }
- s.in(v[i]);
- }
- for(i=x+1;;i++)
- {
- if(s.count(i)==0)
- {
- y=i;
- break;
- }
- }
- for(i=x-1;;i--)
- {
- if(s.count(i)==0)
- {
- z=i;
- break;
- }
- }
- if((y-x)<abs(z-x))
- {
- cout<<y<<endl;
- }
- else if(abs(z-x)<(y-x))
- cout<<z<<endl;
- else
- cout<<min(y,z)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement