fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. #pragma GCC target ("avx2")
  4. #pragma GCC optimization ("O3")
  5. #pragma GCC optimization ("unroll-loops")
  6. #define pii pair<int,int>
  7. #define fi first
  8. #define se second
  9. using namespace std;
  10. using ll = long long;
  11. const int maxN = 1e6 + 10;
  12. const ll infty = 1e18 + 5;
  13. const int mod = 1e9 + 7;
  14.  
  15. int n,m;
  16. int h[maxN];
  17. int t[maxN];
  18.  
  19. void Solve()
  20. {
  21. cin >> n >> m;
  22. multiset<int> st;
  23. for(int i = 1;i <= n;i++)
  24. {
  25. cin >> h[i];
  26. st.insert(h[i]);
  27. }
  28. for(int i = 1;i <= m;i++)
  29. {
  30. cin >> t[i];
  31. auto it = st.upper_bound(t[i]);
  32. if(it == st.begin())
  33. {
  34. cout << -1 <<'\n';
  35. continue;
  36. }
  37. it--;
  38. cout << *it <<'\n';
  39. st.erase(it);
  40. }
  41. }
  42.  
  43. int32_t main()
  44. {
  45. ios_base::sync_with_stdio(false);
  46. cin.tie(nullptr);
  47. int test = 1;
  48. //cin >> test;
  49. while (test--)
  50. {
  51. Solve();
  52. }
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty