aboutsummaryrefslogtreecommitdiff
path: root/02_sorting_and_searching/room_allocation_1164.cpp
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-07-06 19:08:08 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-07-06 19:08:08 +0200
commit96254947699986c59f0dc63d69fd4b76bd3ed43e (patch)
tree6c4dca945d7f7427c48be234d827fe4d33be02c5 /02_sorting_and_searching/room_allocation_1164.cpp
downloadcses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz
cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip
Initial commit
Diffstat (limited to '02_sorting_and_searching/room_allocation_1164.cpp')
-rw-r--r--02_sorting_and_searching/room_allocation_1164.cpp38
1 files changed, 38 insertions, 0 deletions
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 @@
1#include <algorithm>
2#include <iostream>
3#include <queue>
4#include <tuple>
5#include <vector>
6
7int main() {
8 int n;
9 std::vector<std::tuple<int, int, int>> v;
10 std::cin >> n;
11 for (int i = 0; i < n; i++) {
12 int a, b;
13 std::cin >> a >> b;
14 v.push_back({a, b, i});
15 }
16 std::sort(v.begin(), v.end());
17
18 using P = std::pair<int, int>;
19 std::priority_queue<P, std::vector<P>, std::greater<>> r;
20 std::vector<int> al(n);
21 for (auto [a, d, i] : v) {
22 int ind = r.size()+1;
23 if (!r.empty()) {
24 auto [x, j] = r.top();
25 if (a > x) {
26 r.pop();
27 ind = j;
28 }
29 }
30 r.push({d, ind});
31 al[i] = ind;
32 }
33
34 std::cout << r.size() << "\n";
35 for (auto i : al)
36 std::cout << i << " ";
37 std::cout << "\n";
38}

Generated with cgit - Back to sebastiano.tronto.net