fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fst first
  5. #define snd second
  6.  
  7. typedef long long ll;
  8. typedef pair<int, int> ii;
  9.  
  10. const ll LINF = (ll)1e18;
  11. const int INF = (int)1e9;
  12.  
  13. int main() {
  14. ios::sync_with_stdio(0);
  15. cin.tie(0);
  16. int n, m;
  17. cin >> n >> m;
  18.  
  19. multiset<int> tickets;
  20. for (int i = 0; i < n; i++) {
  21. int h; cin >> h;
  22. tickets.insert(h);
  23. }
  24.  
  25. for (int i = 0; i < m; i++) {
  26. int t; cin >> t;
  27. auto it = tickets.upper_bound(t);
  28.  
  29. if (it == tickets.begin()) {
  30. cout << -1 << '\n';
  31. }
  32. else {
  33. --it;
  34. cout << *it << '\n';
  35. tickets.erase(it);
  36. }
  37. }
  38. }
  39.  
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty