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;
#define ll long long
#define pb push_back
const int N = 2e5 + 4;
int n, k, r, a[N], mn[N], cnt[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> r;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < r; ++i) {
int b;
cin >> b;
cin >> mn[b];
}
int ans = INT_MAX;
int l = 0, r = 0, ok = 0;
++cnt[a[0]];
for (int i = 0; i < k; ++i) {
if (cnt[i] >= mn[i]) {
++ok;
}
}
while (l <= r) {
if (ok == k) {
ans = min(ans, r - l + 1);
if (cnt[a[l]] == mn[a[l]]) {
--ok;
}
--cnt[a[l]];
++l;
}
else {
if (r == n - 1) {
break;
}
++r;
if (cnt[a[r]] == mn[a[r]] - 1) {
++ok;
}
++cnt[a[r]];
}
}
if (ans == INT_MAX) {
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... |