cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

concert_tickets_1091.cpp (481B)


      1 #include <algorithm>
      2 #include <iostream>
      3 #include <set>
      4 #include <vector>
      5 
      6 int main() {
      7 	size_t n, m;
      8 	std::cin >> n >> m;
      9 	std::vector<int> hv(n), t(m);
     10 	for (size_t i = 0; i < n; i++)
     11 		std::cin >> hv[i];
     12 	for (size_t i = 0; i < m; i++)
     13 		std::cin >> t[i];
     14 
     15 	std::multiset<int, std::greater<int>> h(hv.begin(), hv.end());
     16 
     17 	for (auto c : t) {
     18 		if (auto x = h.lower_bound(c); x == h.end()) {
     19 			std::cout << "-1\n";
     20 		} else {
     21 			std::cout << *x << "\n";
     22 			h.erase(x);
     23 		}
     24 	}
     25 }