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;
const int N = 202020;
int n, k, r, a[N];
map<int, int> mp;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> k >> r;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 0; i < r; i++) {
int x, y; cin >> x >> y;
mp[x] = y;
}
int cnt = r, ans = 1e9;
for (int i = 1, j = 1; i <= n; i++) {
while (j <= n && cnt) {
if (--mp[a[j]] == 0)
--cnt;
++j;
}
if (cnt == 0)
ans = min(ans, j - i);
if (++mp[a[i]] == 1)
++cnt;
}
if (ans == 1e9)
cout << "impossible";
else
cout << ans;
}
# | 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... |