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 <iostream>
#include <utility>
#include <vector>
int main() {
int n, k, r;
std::cin >> n >> k >> r;
std::vector<int> a(n);
for (int &x : a)
std::cin >> x;
std::vector<int> c(k, 0);
for (int i = 0; i < r; i++) {
int h, q;
std::cin >> h >> q;
c[h] = q;
}
int rr = n+1, bl = 0, br = -1, fn = 0;
std::vector<int> f(k, 0);
while (bl < n) {
while (br < n-1 && fn < r) {
int h = a[++br];
if (++f[h] == c[h])
fn++;
}
if (fn == r)
rr = std::min(rr, br-bl+1);
int h = a[bl++];
if (f[h]-- == c[h])
fn--;
}
if (rr == n+1)
std::cout << "impossible\n";
else
std::cout << rr << '\n';
}
# | 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... |