LowerBound.cpp 1.04 KB
  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
//
// Created by ronal on 2/12/2023.
// Problem Description Link.
// https://www.hackerrank.com/challenges/cpp-lower-bound/copy-from/307592352

#include <bits/stdc.h>

using namespace std;


void PrintLowerBouder(vector<int> values, int queries){
vector<int>::iterator it;
int element;
for(int i = 0; i < queries; i++){
cin >> element;

if(binary_search(values.begin(), values.end(), element)){
it = lower_bound(values.begin(), values.end(), element);
cout << "Yes " << it - values.begin() + 1 << endl;
}else{
it = lower_bound(values.begin(), values.end(), element);
cout << "No " << it - values.begin() + 1 << endl;
}

}
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
vector<int> values;
int size, value, queries, element;

cin >> size;
for(int i = 0; i < size; i++){
cin >> value;
values.push_back(value);
}
cin >> queries;
PrintLowerBouder(values,queries);

return 0;
}