josiftepe

Untitled

Oct 17th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <sstream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <stack>
  10. #include <queue>
  11. #include <cmath>
  12. #include <iomanip>
  13. #include <fstream>
  14. using namespace std;
  15.  
  16. int main() {
  17.     ios_base::sync_with_stdio(false);
  18.     int n, m;
  19.     cin >> n >> m;
  20.     vector<int> tickets(n), customers(m);
  21.     set<pair<int, int>> st;
  22.     for(int i = 0; i < n; ++i) {
  23.         cin >> tickets[i];
  24.         st.insert(make_pair(tickets[i], i));
  25.     }
  26.     for(int i = 0; i < m; ++i) {
  27.         cin >> customers[i];
  28.     }
  29.     // auto : type of variable
  30.     for(int i = 0; i < m; ++i) {
  31.         auto it = st.lower_bound(make_pair(customers[i] + 1, 0));
  32.         if(it == st.begin()) {
  33.             cout << -1 << '\n';
  34.         }
  35.         else {
  36.             --it;
  37.             cout << it->first << endl;
  38.             st.erase(it);
  39.         }
  40.     }
  41.     // {st.begin | (5, 1), (5, 2), (7, 3) st.end()}
  42.     // (4, 0)
  43.     // (9, 0)
  44.     //(4, 0)
  45.  
  46.    
  47.     return 0;
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. /*
  58.  
  59.  5 3
  60.   5, 5, 7, 8 : ticket price
  61.  4 8 3 : maximum price each customer is willing to pay
  62.  
  63.  output:
  64.  3, 8, -1
  65. */
  66.  
Advertisement
Add Comment
Please, Sign In to add comment