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>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, K, R;
cin >> N >> K >> R;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> B(K);
for (int i = 0; i < R; i++) {
int x, y;
cin >> x >> y;
B[x] = y;
}
int ans = N + 1;
int bad = R;
vector<int> freq(K);
const auto Modify = [&](int k, int sgn) {
bad -= freq[k] < B[k];
freq[k] += sgn;
bad += freq[k] < B[k];
};
for (int i = 0, j = 0; i < N; i++) {
Modify(A[i], +1);
while (bad == 0) {
Modify(A[j], -1);
if (bad == 0) {
j += 1;
} else {
Modify(A[j], +1);
break;
}
}
if (bad == 0) {
ans = min(ans, i - j + 1);
}
}
if (ans > N) {
cout << "impossible\n";
} else {
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... |