Josif_tepe

Untitled

Dec 23rd, 2025
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. #include <set>
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n, m;
  9.     cin >> n >> m;
  10.  
  11.     multiset<long long> tickets;
  12.     for (int i = 0; i < n; i++) {
  13.         long long x;
  14.         cin >> x;
  15.         tickets.insert(x);
  16.     }
  17.  
  18.  
  19.  
  20.     int ta = n;
  21.  
  22.     for (int i = 0; i < m; i++) {
  23.         long long x;
  24.         cin >> x;
  25.  
  26.        
  27.     multiset<long long>::iterator it = tickets.lower_bound(x + 1);
  28.        
  29.         if(it == tickets.begin()) {
  30.             cout << -1 << "\n";
  31.            
  32.         }
  33.         else {
  34.             it--;
  35.             cout << *it << "\n";
  36.             tickets.erase(it);
  37.         }
  38.  
  39.        
  40.            
  41.            
  42.            
  43.         }
  44.    
  45.  
  46.     return 0;
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment