#include <bits/stdc++.h>
using namespace std;
bool valid(map<int,int> &req, map<int,int> ¤t) {
if(current.size() < req.size()) return false;
for(auto &[key, value] : req) {
if(current[key] < value) return false;
}
return true;
}
int main() {
int N, K, R;
cin >> N >> K >> R;
vector<int> dna(N);
for(int i = 0; i < N; i++) {
cin >> dna[i];
}
map<int, int> req;
for(int i = 0; i < R; i++) {
int a, b;
cin >> a >> b;
req[a] = b;
}
int ans = INT_MAX;
//sliding window
map<int,int> current;
int l(0), r(0); //no elements selected
while(l<=r && r < N) {
// cout << l << " " << r << "\n";
if(!valid(req, current)) { //not valid
current[dna[r]] += 1;
r++;
}
else {
ans = min(ans, r-l);
current[dna[l]] -= 1;
l++;
}
}
if(ans == INT_MAX) {
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... |