#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define se second
#define pb push_back
#define fi first
#define fo(var, n) for(long long var=0;var<n;var++)
#define fore(var, n) for(long long var=n-1;var>=0;var--)
using namespace std;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int tt = 1;
//cin>>tt;
while(tt--)
{
int n,k,r; cin>>n>>k>>r;
int a[n];
fo(i,n) cin>>a[i];
int b[k];
fo(i,k) b[i]=0;
fo(i,r)
{
int t,c; cin>>t>>c;
b[t] = c;
}
int i = 0,j=0;
int c[k];
fo(i,k) c[i] = 0;
int hav=0;
int ans=1e8;
while(i< n && j<n)
{
while(i<n && hav != r)
{
c[a[i]] ++; if(c[a[i]] == b[a[i]]) hav++; i++;
}
while(j<n)
{
if(c[a[j]] == b[a[j]]) break;
c[a[j]] --; j++;
}
if(j == n) break;
ans=min(ans, i-j);
c[a[j]] --; j++;
hav--;
}
if(ans == 1e8) cout<<"impossible\n";
else cout<<ans<<"\n";
}
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... |