Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<algorithm>
- using namespace std;
- int BinarySearch(int number,int x[],int n) {
- int lower = 0, upper = n - 1;
- int ans = -1;
- while (lower <= upper) {
- int mid = (upper + lower) / 2;
- if (x[mid] > number) {
- upper = mid - 1;
- }
- else {
- ans = mid;
- lower = mid + 1;
- }
- }
- return ans+ 1;
- }
- int main()
- {
- int n,m;
- cin>>n>>m;
- int x[n],y[m];
- for(int i=0; i<n; i++)
- {
- cin>>x[i];
- }
- sort(x,x+n);
- for(int i=0; i<m; i++)
- {
- cin>>y[i];
- cout<<BinarySearch(y[i],x,n)<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement