Advertisement
Josif_tepe

Untitled

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