This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main() {
int n, k, m;
cin >> n >> k >> m;
vector<int> v(n);
for(int i = 0; i < n; i++) {
cin >> v[i];
}
vector<int> req(k + 1, 0);
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
req[a] = b;
}
int j = 0;
int cnt = m;
int res = 2e9;
for(int i = 0; i < n; i++) {
while(cnt > 0 and j < n) {
req[v[j]]--;
if(req[v[j]] == 0) {
cnt--;
}
j++;
}
if(cnt == 0) {
res = min(res, j - i);
}
req[v[i]]++;
if(req[v[i]] > 0) {
cnt++;
}
}
if(res == 2e9) {
cout << "impossible" << endl;
}
else {
cout << res << endl;
}
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... |