-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp-lower-bound.cpp
More file actions
37 lines (28 loc) · 893 Bytes
/
Copy pathcpp-lower-bound.cpp
File metadata and controls
37 lines (28 loc) · 893 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
36
37
#include <vector>
#include <iostream>
#include <algorithm>
int main()
{
auto vect = std::vector<unsigned>{};
auto size = std::size_t{};
auto elem = decltype(vect)::value_type{};
std::cin >> size;
vect.reserve(size);
for (auto i = std::size_t{0}; i < size; i++) {
std::cin >> elem;
vect.emplace_back(elem);
}
auto noOfQueries = unsigned{};
std::cin >> noOfQueries;
auto iter = decltype(vect)::iterator{};
auto searched = unsigned{};
auto position = std::size_t{};
for (auto i = decltype(noOfQueries){0}; i < noOfQueries; i++) {
std::cin >> searched;
iter = lower_bound(vect.begin(), vect.end(), searched);
position = iter - vect.begin() + 1;
std::cout << (*iter == searched ? "Yes " : "No ");
std::cout << position << '\n';
}
return 0;
}