goshansmails

Untitled

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