Advertisement
Josif_tepe

Untitled

Jun 1st, 2024
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n, m;
  9.     cin >> n >> m;
  10.  
  11.     multiset<int> ms;
  12.     for(int i = 0; i < n; i++) {
  13.         int x;
  14.         cin >> x;
  15.  
  16.         ms.insert(x);
  17.     }
  18.     int niza[m];
  19.     for(int i = 0; i < m; i++) {
  20.         cin >> niza[i];
  21.     }
  22.     for(int i = 0; i < m; i++) {
  23.         auto it = ms.lower_bound(niza[i] + 1);
  24.        
  25.         if(it == ms.begin()) {
  26.             cout << -1 << endl;
  27.         }
  28.         else {
  29.             it--;
  30.             cout << *it << endl;
  31.             ms.erase(it);
  32.         }
  33.     }
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement