이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
template <class T>
using Vec = std::vector<T>;
int main() {
int N, K, R;
std::cin >> N >> K >> R;
Vec<int> A(N);
for (auto& x: A) {
std::cin >> x;
}
Vec<Vec<int>> pos(K);
for (int i = 0; i < N; ++i) {
pos[A[i]].push_back(i);
}
Vec<int> need(K);
while (R--) {
int b;
std::cin >> b;
std::cin >> need[b];
}
int right = 0;
for (int i = 0; i < K; ++i) {
if (need[i] == 0) {
continue;
}
if (need[i] > (int) pos[i].size()) {
std::cout << "impossible\n";
return 0;
}
right = std::max(right, pos[i][need[i] - 1]);
}
int ans = right + 1;
for (int left = 1; left < N; ++left) {
const auto x = A[left - 1];
if (need[x] > 0) {
need[x] += 1;
if (need[x] > (int) pos[x].size()) {
break;
}
right = std::max(right, pos[x][need[x] - 1]);
}
ans = std::min(ans, right - left + 1);
}
std::cout << ans << '\n';
return 0;
}
# | 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... |