Advertisement
Josif_tepe

Untitled

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