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>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 2e5 + 5;
int a[mxN];
int cnt[mxN];
void testCase() {
int n, k, r;
cin >> n >> k >> r;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i < r; i++) {
int a, b;
cin >> a >> b;
cnt[a] = b;
}
int cc = r;
int ptr = 1;
int ans = n + 1;
for (int i = 1; i <= n; i++) {
while (ptr <= n && cc) {
cnt[a[ptr]]--;
if (cnt[a[ptr]] == 0) cc--;
ptr++;
}
if (!cc) ans = min(ans, ptr - i);
cnt[a[i]]++;
if (cnt[a[i]] == 1) cc++;
}
if (ans == n + 1) cout << "impossible\n";
else cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
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... |