#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename key>
// for ordered set or indexed set
#define f1(n) for(int i=0;i<n;i++)
#define e '\n'
#define f2(m,n,q) for(int i=m;i<n;i+=q)
#define f3(n) for(int j=0;j<n;j++)
#define f4(m,n,q) for(int j=m;j<n;j+=q)
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
//f^=1 == if(f==0)f=1 else f=0
const int N=2e5+5;
const int mod=1e9+7;
const int inf=1e9,sqr=448;
int32_t main()
{
speed;
int tt=1;//cin>>tt;
while(tt--){
//freopen("teamwork.in","r",stdin);
//freopen("teamwork.out","w",stdout);
int n,k,r;cin>>n>>k>>r;
int a[n];f1(n)cin>>a[i];
map<int,int>mp;
pair<int,int>pr[r];f1(r)cin>>pr[i].first>>pr[i].second,mp[pr[i].first]=pr[i].second;
int ans=inf;
f1(n){
int frq[n+1]={};
for(int j=i;j<n;j++){
frq[a[j]]++;
bool fl=1;
for(auto it:mp){
if(frq[it.first]<it.second){fl=0;break;}
}
if(fl)ans=min(ans,j-i+1);
}
}
if(ans==inf)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... |