#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k, r, c, a, b, ans=LLONG_MAX/2;
cin>>n>>k>>r, c=k-r;
vector<int> vect(n), count(k, 0), req(k, 0);
for (int i=0; i<n; ++i)cin>>vect[i];
while (r--){
cin>>a>>b;
req[a]=b;
}
for (int l=0, r=0; r<n; ++r){
++count[vect[r]];
if (count[vect[r]]==req[vect[r]])++c;
while (c==k){
ans=min(ans, r-l+1);
if (count[vect[l]]==req[vect[l]])--c;
--count[vect[l]];
++l;
}
}
if (ans==LLONG_MAX/2)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... |