This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
int main() {
int N, K, R;
std::cin >> N >> K >> R;
std::vector<int> D(N);
for (auto &e : D) {
std::cin >> e;
}
std::vector<std::vector<int>> index_list(K);
for (int i = 0; i < N; ++i) {
index_list[D[i]].push_back(i);
}
std::vector<std::vector<std::pair<int, bool>>> events(N + 1);
while (R--) {
int B, Q;
std::cin >> B >> Q;
const auto &list = index_list[B];
if ((int)list.size() < Q) {
events[0].push_back({3 * N, true});
break;
}
events[0].push_back({list[Q - 1], true});
for (int i = 0; i < (int)list.size() - Q; ++i) {
events[list[i] + 1].push_back({list[i + Q - 1], false});
events[list[i] + 1].push_back({list[i + Q], true});
}
events[list[(int)list.size() - Q] + 1].push_back({3 * N, true});
}
std::multiset<int> mls;
int answer = N;
for (int i = 0; i < N; ++i) {
for (const auto &[v, b] : events[i]) {
if (b) {
mls.insert(v);
} else {
mls.erase(mls.find(v));
}
}
answer = std::min(answer, *mls.rbegin() - i + 1);
}
if (answer == N) {
std::cout << "impossible" << std::endl;
} else {
std::cout << answer << std::endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |