From 96254947699986c59f0dc63d69fd4b76bd3ed43e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 6 Jul 2026 19:08:08 +0200 Subject: Initial commit --- 02_sorting_and_searching/room_allocation_1164.cpp | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 02_sorting_and_searching/room_allocation_1164.cpp (limited to '02_sorting_and_searching/room_allocation_1164.cpp') diff --git a/02_sorting_and_searching/room_allocation_1164.cpp b/02_sorting_and_searching/room_allocation_1164.cpp new file mode 100644 index 0000000..f79cc96 --- /dev/null +++ b/02_sorting_and_searching/room_allocation_1164.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +int main() { + int n; + std::vector> v; + std::cin >> n; + for (int i = 0; i < n; i++) { + int a, b; + std::cin >> a >> b; + v.push_back({a, b, i}); + } + std::sort(v.begin(), v.end()); + + using P = std::pair; + std::priority_queue, std::greater<>> r; + std::vector al(n); + for (auto [a, d, i] : v) { + int ind = r.size()+1; + if (!r.empty()) { + auto [x, j] = r.top(); + if (a > x) { + r.pop(); + ind = j; + } + } + r.push({d, ind}); + al[i] = ind; + } + + std::cout << r.size() << "\n"; + for (auto i : al) + std::cout << i << " "; + std::cout << "\n"; +} -- cgit v1.3