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 <bits/stdc++.h>
using namespace std;
int n, k, r, req[100010], amt[100010], qu, ans = 1e9, p1 = 0, p2 = 0;
vector<int> dna;
void add(int type) {
if(req[type] == 0) return;
if(req[type] == amt[type]+1) {
qu++;
}
amt[type]++;
}
void del(int type) {
if(req[type] == 0) return;
if(req[type] == amt[type]) {
qu--;
}
amt[type]--;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k >> r;
for(int i=1; i<=n; i++) {
int in;
cin >> in;
dna.push_back(in);
}
for(int i=1; i<=r; i++) {
int b, q;
cin >> b >> q;
req[b] = q;
}
while(p2 < n) {
if(qu == r) {
ans = min(ans, p2-p1);
del(dna[p1]);
p1++;
} else {
add(dna[p2]);
p2++;
}
}
if(ans == 1e9) {
cout << "impossible";
} else {
cout << 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... |