You are viewing a single comment's thread. Return to all comments →
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int m, num; cin >> m; vector<int> v; for (int i=0; i<m; i++){ cin >> num; v.push_back(num); } int n, val; cin >> n; for (int i=0; i<n; i++){ cin >> val; vector<int>::iterator low = lower_bound(v.begin(), v.end(), val); if (v[low - v.begin()] == val) cout << "Yes " << (low - v.begin()+1) << endl; else cout << "No " << (low - v.begin()+1) << endl; } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Lower Bound-STL
You are viewing a single comment's thread. Return to all comments →