Advertisement
Farjana_akter

Untitled

Feb 1st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int a,n,q,b,i,j,k,low,hi;
  6. vector<int>v;
  7. cin>>n;
  8. for(i=0;i<n;i++)
  9. {
  10. cin>>a;
  11. v.push_back(a);
  12. }
  13. cin>>q;
  14. for(i=1;i<=q;i++)
  15. {
  16. cin>>b;
  17. low=lower_bound(v.begin(),v.end(),b)-v.begin();
  18. hi=upper_bound(v.begin(),v.end(),b)-v.begin();
  19. if(low==0)
  20. cout<<"X ";
  21. else
  22. cout<<v[low-1]<<" ";
  23. if(hi==n)
  24. cout<<"X"<<endl;
  25. else if(v[hi]!=b)
  26. cout<<v[hi]<<endl;
  27. else
  28. cout<<v[hi]<<endl;
  29.  
  30. }
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement