Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int a,n,q,b,i,j,k,low,hi;
- vector<int>v;
- cin>>n;
- for(i=0;i<n;i++)
- {
- cin>>a;
- v.push_back(a);
- }
- cin>>q;
- for(i=1;i<=q;i++)
- {
- cin>>b;
- low=lower_bound(v.begin(),v.end(),b)-v.begin();
- hi=upper_bound(v.begin(),v.end(),b)-v.begin();
- if(low==0)
- cout<<"X ";
- else
- cout<<v[low-1]<<" ";
- if(hi==n)
- cout<<"X"<<endl;
- else if(v[hi]!=b)
- cout<<v[hi]<<endl;
- else
- cout<<v[hi]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement