fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int isFound(vector<int>v,int k,int l,int r)
  5. {
  6.  
  7. while(l<=r)
  8. {
  9. int m=l+(r-l)/2;
  10. if(v[m]<k)
  11. return isFound(v,k,m+1,r);
  12. else if(v[m]>k)
  13. return isFound(v,k,l,m-1);
  14. else
  15. return k;
  16. }
  17. return -1;
  18. }
  19. int main() {
  20. int n,k;
  21. cin>>n>>k;
  22. vector<int>v(n);
  23. for(int i=0;i<n;i++)
  24. {
  25. cin>>v[i];
  26. }
  27. int l=0,r=n-1;
  28. int c=isFound(v,k,l,r);
  29. if(c==k)
  30. cout<<"true";
  31. else
  32. cout<<"false";
  33. return 0;
  34. }
Success #stdin #stdout 0s 5516KB
stdin
5 1
2 19 23 35 38
stdout
false