-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcpp-lower-bound.cpp
More file actions
36 lines (27 loc) · 805 Bytes
/
cpp-lower-bound.cpp
File metadata and controls
36 lines (27 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Lower Bound-STL
// Given N numbers, you have to find the smallest integer greater than the given number and print the index of that number.
//
// https://www.hackerrank.com/challenges/cpp-lower-bound/problem
//
#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 */
vector<int> v;
int n, q;
cin >> n;
while (n--) { int i; cin >> i; v.push_back(i); }
cin >> n;
while (n-- != 0)
{
cin >> q;
vector<int>::const_iterator r = lower_bound(v.begin(), v.end(), q);
cout << ((*r == q) ? "Yes " : "No ")
<< 1 + (r - v.begin()) << endl;
}
return 0;
}