summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-03-21 23:03:47 +0800
committercrupest <crupest@outlook.com>2021-03-21 23:03:47 +0800
commita2fd778dfca45cb2a3471647427e6b409f76de80 (patch)
tree181ae449c9ef7f11f386b5ac51ccc0a5133aab6a
parent7462afc30f0de1add49b1bc708224100d510ba55 (diff)
downloadsolutions-a2fd778dfca45cb2a3471647427e6b409f76de80.tar.gz
solutions-a2fd778dfca45cb2a3471647427e6b409f76de80.tar.bz2
solutions-a2fd778dfca45cb2a3471647427e6b409f76de80.zip
Add acwing 1238.
-rw-r--r--acwing/1238.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/acwing/1238.cpp b/acwing/1238.cpp
new file mode 100644
index 0000000..2c9d899
--- /dev/null
+++ b/acwing/1238.cpp
@@ -0,0 +1,56 @@
+#include <iostream>
+#include <map>
+#include <set>
+
+const int M = 100010;
+
+int N, D, K;
+
+std::map<int, std::multiset<int>> vote_map;
+
+bool check(const std::multiset<int> &v) {
+ auto iter1 = v.cbegin();
+ auto iter2 = v.cbegin();
+
+ const auto end = v.cend();
+
+ int count = 1;
+
+ while (iter2 != end) {
+ while (*iter2 - *iter1 >= D) {
+ ++iter1;
+ count--;
+ }
+
+ if (count >= K)
+ return true;
+
+ ++iter2;
+ count++;
+ }
+
+ return false;
+}
+
+int main() {
+ std::ios_base::sync_with_stdio(false);
+ std::cin.tie(nullptr);
+
+ std::cin >> N >> D >> K;
+
+ for (int i = 1; i <= N; i++) {
+ int ts, id;
+ std::cin >> ts >> id;
+ vote_map[id].insert(ts);
+ }
+
+ int result;
+
+ for (const auto &vote : vote_map) {
+ if (check(vote.second)) {
+ std::cout << vote.first << "\n";
+ }
+ }
+
+ return 0;
+}