Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define ll long long
- #define int long long
- const int inf = 1e18;
- ll M2 = 1e9 + 9, M1 = 1e9 + 7;
- //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
- void solve() {
- int n, m;
- cin >> n >> m;
- vector<int> a(n);
- vector<int> b(m);
- for (auto &x : a) {
- cin >> x;
- }
- for (auto &x : b) {
- cin >> x;
- int l = 0, r = n;
- while (r - l > 1) {
- int mid = (r + l) / 2;
- if (a[mid] > x) {
- r = mid;
- } else {
- l = mid;
- }
- }
- int mn = inf, res = inf;
- for (int i = l; i <= min(n - 1, r); ++i) {
- if (abs(a[i] - x) < mn) {
- mn = abs(a[i] - x);
- res = a[i];
- }
- }
- cout << res << '\n';
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- ll thrush = 1;
- //cin >> thrush;
- while (thrush--) { solve();}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement