# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789466 | Trisanu_Das | Martian DNA (BOI18_dna) | C++17 | 0 ms | 0 KiB |
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;
long long n, k, cnt, x, a[200010], b[200010], c[200010], l = 1, r, minn = 1e18;
int main() {
cin >> n >> k >> cnt;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= cnt; i++) {
cin >> x;
cin >> b[x];
}
while (r <= n) {
if (cnt) {
r++;
c[a[r]]++;
if (c[a[r]] == b[a[r]]) cnt--;
} else {
minn = min(minn,r-l+1);
if (c[a[l]] == b[a[l]]) cnt++;
c[a[l]]--;
l++;
}
}
if (minn == 1e18) cout << "impossible" << endl;
else cout << minn << endl;
}e