fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define for1(i,m,n) for(int i=m;i<=n;i++)
  5. #define for0(i,m,n) for(int i=m;i<n;i++)
  6.  
  7. #define int long long
  8. #define el '\n'
  9. #define fi first
  10. #define se second
  11. #define ii pair<int,int>
  12. #define vll(i) i.begin(),i.end()
  13.  
  14. const int N=1e7;
  15. const int mod=1e9+7;
  16.  
  17. int a[N],b[N];
  18. multiset<int>s;
  19. signed main(){
  20. ios_base::sync_with_stdio(0);
  21. cin.tie(0);
  22. cout.tie(0);
  23. // freopen("bai1.INP","r",stdin);
  24. // freopen("bai1.OUT","w",stdout);
  25. int n,k;cin>>n>>k;
  26. for1(i,1,n) {
  27. int x;cin>>x;
  28. s.insert(x);
  29. }
  30.  
  31. for1(i,1,k){
  32. int x;cin>>x;
  33.  
  34. auto y=s.upper_bound(x);
  35. if(y==s.begin()){
  36. cout<<-1<<el;
  37. }
  38. else {
  39. //*******
  40. y=prev(y);
  41. //*****
  42. cout<<*y<<el;
  43. s.erase(y);
  44. }
  45. }
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
140736914891400
-1