Untitled
unknown
c_cpp
9 months ago
651 B
2
Indexable
#include <iostream> #include <set> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; set<int> a; for (int i=0; i<n; i++) { int x; cin >> x; a.insert(x); } while (m--) { int x; cin >> x; auto rb = a.lower_bound(x); if (rb == a.end()) cout << *prev(rb) << endl; else if (rb != a.begin()) { auto lb = prev(rb); cout << ((*rb - x < x - *lb) ? *rb : *lb) << endl; } else cout << *rb << endl; } }
Editor is loading...
Leave a Comment