Josif_tepe

Untitled

Dec 23rd, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n, m;
  9.     cin >> n >> m;
  10.  
  11.     long long tickets[200000];
  12.     for (int i = 0; i < n; i++) {
  13.         cin >> tickets[i];
  14.     }
  15.  
  16.  
  17.     sort(tickets, tickets + n);
  18.  
  19.     int ta = n;
  20.  
  21.     for (int i = 0; i < m; i++) {
  22.         long long x;
  23.         cin >> x;
  24.  
  25.         int left = 0, right = ta - 1;
  26.         int pos = -1;
  27.  
  28.  
  29.         while (left <= right) {
  30.             int mid = (left + right) / 2;
  31.  
  32.             if (tickets[mid] <= x) {
  33.                 pos = mid;
  34.                 left = mid + 1;
  35.             } else {
  36.                 right = mid - 1;
  37.             }
  38.         }
  39.  
  40.         if (pos == -1) {
  41.             cout << -1 << '\n';
  42.         } else {
  43.             cout << tickets[pos] << '\n';
  44.  
  45.  
  46.             for (int j = pos; j < ta - 1; j++) {
  47.                 tickets[j] = tickets[j + 1];
  48.             }
  49.             ta--;
  50.         }
  51.     }
  52.  
  53.     return 0;
  54. }
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment