Posted on

The function returns an iterator for the least number that is bigger or equals to the target number.

#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> v;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int t;
        cin >> t;
        v.push_back(t);
    }
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++) {
        int q;
        cin >> q;
        vector<int>::iterator r = lower_bound(v.begin(), v.end(), q);
        if(v.at(r - v.begin()) == q) cout << "Yes "; 
        else cout << "No ";
        cout << r - v.begin() + 1 << endl;
    }
    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *