Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- //#include <bits/stdc++.h>
- using namespace std;
- const int maxn = 1e5 + 10;
- int main()
- {
- int n, x;
- cin >> n >> x;
- int a[n];
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- int L = 0, R = n - 1;
- while(L <= R) {
- int middle = (L + R) / 2;
- if(x == a[middle]) {
- cout << "Found at: " << middle << endl;
- break;
- }
- if(x < a[middle]) {
- R = middle - 1;
- }
- else {
- L = middle + 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment