We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>usingnamespacestd;intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT *///taking inputintn{};cin>>n;vector<int>v;for(inti{0};i<n;++i){intt{};cin>>t;v.push_back(t);}// s is number of queriesints;cin>>s;// foreach query, get the value and print necessary valuefor(inti{0};i<s;++i){intnum{};cin>>num;// lower bound returns an iterator type variablevector<int>::iteratorx;x=lower_bound(v.begin(),v.end(),num);// getting the index of the lowerbound in the vectorintpos=x-v.begin();// if value of lb = the query num, then yes it exists// in the vector existsif(v[pos]==num)cout<<"Yes "<<pos+1;elsecout<<"No "<<pos+1;cout<<endl;}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lower Bound-STL
You are viewing a single comment's thread. Return to all comments →