This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: wxhtzdy
* created: 10.11.2022 15:50:40
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, r;
cin >> n >> k >> r;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> need(k, -1);
for (int i = 0; i < n; i++) {
int b, q;
cin >> b >> q;
need[b] = q;
}
int cnt_good = 0;
vector<int> cnt(k);
int ptr = -1;
int ans = n + 1;
auto Add = [&](int x) {
cnt[x] += 1;
if (cnt[x] == need[x]) {
cnt_good += 1;
}
};
auto Remove = [&](int x) {
if (cnt[x] == need[x]) {
cnt_good -= 1;
}
cnt[x] -= 1;
};
for (int i = 0; i < n; i++) {
while (ptr + 1 < n && cnt_good < r) {
ptr += 1;
Add(a[ptr]);
}
if (cnt_good == r) {
ans = min(ans, ptr - i + 1);
}
Remove(a[i]);
}
if (ans > n) {
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... |