#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
int cnt[N];
int a[N];
int req[N];
int p;
void add(int x){
cnt[a[x]]++;
if(cnt[a[x]]==req[a[x]])p++;
}
void rem(int x){
cnt[a[x]]--;
if(cnt[a[x]]==req[a[x]]-1)p--;
}
signed main(){
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)cin>>a[i];
p=m-k;
for(int i=1;i<=k;i++){
int x;
cin>>x;
cin>>req[x];
}
int l=1,r=0;
int ans=1e9;
while(r<=n){
if(p==m){
ans=min(ans,r-l+1);
rem(l++);
}
else{
add(++r);
}
}
if(ans==1e9){
cout<<"impossible";
return 0;
}
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... |