#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k, R;
cin >> n >> k >> R;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
vector<int> cnt(k, -1), have(k);
for (int i = 0; i < R; i++) {
int type, need;
cin >> type >> need;
cnt[type] = need;
}
int ok = 0, r = 0, ans = 1e9;
for (int i = 0; i < n; i++) {
while (r < n && ok != R) {
have[v[r]]++;
if (have[v[r]] == cnt[v[r]]) ok++;
r++;
}
if (ok == R) ans = min(ans, r - i);
if (have[v[i]] == cnt[v[i]]) ok--;
have[v[i]]--;
}
if (ans == 1e9) cout << "impossible";
else cout << ans;
}
# | 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... |