aboutsummaryrefslogtreecommitdiff
path: root/codeforces/closestToTheLeft/main.cpp
blob: d058458d6e6b6cc523e9d7b1ff10f9846d70bd52 (plain)
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
#include <bits/stdc++.h>

using namespace std;

int bs(vector<int> &a, int toFind) {
  int low = -1;
  int high = a.size();
  int mid = (high + low) / 2;
  while (low + 1 < high) {
    if (a[mid] <= toFind) {
      low = mid;
    } else { 
      high = mid;
    }
    mid = (high + low) / 2;
  }
  return low;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;

  vector<int> a(n);
  vector<int> q(n);

  for (int &x : a)
    cin >> x;
  for (int i = 0; i < k; i++) {
    int y;
    cin >> y;
    cout << bs(a, y) + 1 << endl;
  }
}