#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#define int ll
const int mxn = 4e5+10;
int cnt[mxn];
int N,K,Q;
int arr[mxn];
int good = 0;
int lim[mxn];
inline void add(int k){
cnt[k]++;
if(cnt[k] == lim[k])good++;
return;
}
inline void del(int k){
if(cnt[k] == lim[k])good--;
cnt[k]--;
return;
}
inline bool check(int len){
memset(cnt,0,sizeof(cnt));
good = 0;
for(int i = 0;i<K;i++){
if(!lim[i])good++;
}
for(int i = 1;i<len;i++){
add(arr[i]);
}
for(int i = len;i<=N;i++){
add(arr[i]);
if(good == K)return true;
del(arr[i-len+1]);
}
return false;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>K>>Q;
for(int i = 1;i<=N;i++)cin>>arr[i];
while(Q--){
int a,b;
cin>>a>>b;
lim[a] = b;
}
int l = 0,r = N;
while(l != r){
int mid = (l+r)>>1;
if(check(mid))r = mid;
else l = mid+1;
}
if(check(l))cout<<l;
else cout<<"impossible";
}
Compilation message
cc1plus: error: '::main' must return 'int'