Created
May 7, 2019 15:39
-
-
Save lazycipher/69d26eb3dc378af0f9fa7bb0adb6ff03 to your computer and use it in GitHub Desktop.
HackerRank Problem Lower Bound-STL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main() { | |
int n,q; | |
vector<int> N; | |
cin>>n; | |
while(n){ | |
int val; | |
cin>>val; | |
N.push_back(val); | |
n--; | |
} | |
cin>>q; | |
while(q){ | |
int query; | |
vector<int>::iterator low; | |
cin >> query; | |
low = lower_bound(N.begin(), N.end(), query); | |
if(N[low - N.begin()] == query) { | |
cout << "Yes " << (low - N.begin() +1 ) <<endl; | |
}else{ | |
cout<<"No "<<(low - N.begin() +1) <<endl; | |
} | |
q--; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment