#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> veci;
typedef vector<ll> vecll;
#define fi first
#define se second
#define debug(x) cerr<<# x<<" is "<<x<<'\n'
#define vec vector
#define pq priority_queue
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, k, r;
cin >> n >> k >> r;
int d[n], req[k]={0}, i;
for (i=0; i<n; i++) {
cin >> d[i];
}
for (i=0; i<r; i++) {
int b, q;
cin >> b >> q;
req[b] = q;
}
int cnt[k]={0}, f=0, ans=INT_MAX;
int left=0, right=0;
cnt[d[0]]++;
if (cnt[d[0]] == req[d[0]]) {
f++;
}
while (right<n) {
if (f!=r) {
right++;
if (right>=n) break;
cnt[d[right]]++;
if (cnt[d[right]] == req[d[right]]) {
f++;
}
} else {
//cout << "hi\n";
ans = min(ans, (right-left+1));
if (ans==1) break;
left++;
cnt[d[left-1]]--;
if (cnt[d[left-1]] == req[d[left-1]]-1) {
f--;
}
}
}
cout << (ans==INT_MAX ? "impossible" : to_string(ans));
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... |