-
Notifications
You must be signed in to change notification settings - Fork 54
/
Lower Bound-STL.cpp
42 lines (37 loc) · 986 Bytes
/
Lower Bound-STL.cpp
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
36
37
38
39
40
41
42
/*
-- # Problem Link : https://www.hackerrank.com/challenges/cpp-lower-bound/problem?isFullScreen=true
-- # Problem : Lower Bound-STL
-- # Language : C++
-- # Subdomain : STL
-- # Max Score : 15
-- # Difficulty : Easy
*/
#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;
}