Input Format
The first line of the input contains the number of integers . The next line contains  integers in sorted order. The next line contains , the number of queries. Then  lines follow each containing a single integer .
Note that if the same number is present multiple times, you have to print the first index at which it occurs. Also, the input is such that you always have an answer for each query.
Constraints

,where  is  element in the array.

Output Format
For each query you have to print "Yes" (without the quotes) if the number is present and at which index(1-based) it is present separated by a space.
If the number is not present you have to print "No" (without the quotes) followed by the index of the next smallest number just greater than that number.
You have to output each query in a new line.

hackerrank lower bound stl problem solution in c++ programming

Lower Bound STL problem solution in C++ programming | HackerRank


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int n;
    vector<int> vec;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        vec.push_back(temp);
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int temp;
        cin >> temp;
        vector<int>::iterator iter;
        iter = lower_bound(vec.begin(), vec.end(), temp);
        if (*(iter + 1) == temp || *iter == temp)
            cout << "Yes " << iter - vec.begin() + 1 << endl;
        else
            cout << "No " << iter - vec.begin() + 1 << endl;
    }
    return 0;
}