#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, k, m; cin>>n>>k>>m;
    vector<int> x(n + 1);
    for (int i = 1; i <= n; i++){
        cin>>x[i];
    }
    vector<int> v(n + 1);
    int cc = m;
    while (m--){
        int a, b; cin>>a>>b;
        v[a] = -b;
    }
    int l = 1, r = 1, out = 1e9;
    while (l <= n){
        while (r <= n && cc){
            v[x[r]]++;
            if (v[x[r]] == 0) cc--;
            r++;
        }
        if (!cc) out = min(out, r - l);
        v[x[l]]--;
        if (v[x[l]] == -1) cc++;
        l++;
    }
    
    if (out == 1e9){
        cout<<"impossible"<<"\n";
    }
    else {
        cout<<out<<"\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... |