fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n,target;
  6. cin>>n>>target;
  7. vector<int> arr(n);
  8. for(int i=0;i<n;i++){
  9. cin>>arr[i];
  10. }
  11. int count=0;
  12. int l=0,r=n-1;
  13. while(l<=r){
  14. int mid=(l+r)/2;
  15. if(arr[mid]==target){
  16. count=1;
  17. break;
  18. }if(arr[mid]<target){
  19. l=mid+1;
  20. }else{
  21. r=mid-1;
  22. }
  23. }
  24. if(count==1){
  25. cout<<"True"<<endl;
  26. }else{
  27. cout<<"False"<<endl;
  28. }
  29. }
Success #stdin #stdout 0.01s 5280KB
stdin
5 19
2 19 23 35 38
stdout
True