Advertisement
ivangarvanliev

Untitled

Jun 2nd, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. int n, m;
  2.     cin >> n >> m;
  3.  
  4.     multiset<int> ms;
  5.     for(int i = 0; i < n; i++) {
  6.         int x;
  7.         cin >> x;
  8.  
  9.         ms.insert(x);
  10.     }
  11.     int niza[m];
  12.     for(int i = 0; i < m; i++) {
  13.         cin >> niza[i];
  14.     }
  15.     for(int i = 0; i < m; i++) {
  16.         auto it = ms.lower_bound(niza[i] + 1);
  17.        
  18.         if(it == ms.begin()) {
  19.             cout << -1 << endl;
  20.         }
  21.         else {
  22.             it--;
  23.             cout << *it << endl;
  24.             ms.erase(it);
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement