Skip to content

Instantly share code, notes, and snippets.

@lazycipher
Created May 7, 2019 15:39
Show Gist options
  • Save lazycipher/69d26eb3dc378af0f9fa7bb0adb6ff03 to your computer and use it in GitHub Desktop.
Save lazycipher/69d26eb3dc378af0f9fa7bb0adb6ff03 to your computer and use it in GitHub Desktop.
HackerRank Problem Lower Bound-STL
#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