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>
#define ll long long
using namespace std;
const int N = 2e5 + 5;
const ll inf = 1e18;
int n, k, R;
int a[N], need[N];
int cnt[N], done, ans = 1e9;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k >> R;
for (int i = 1; i <= n; ++ i) cin >> a[i];
for (int i = 1; i <= R; ++ i) {
int x, y;
cin >> x >> y;
need[x] = y;
}
int l = 1, r = 0;
while (r < n) {
++ r;
++ cnt[a[r]];
if (cnt[a[r]] == need[a[r]]) ++ done;
while (l <= r && done == R) {
ans = min(ans, r - l + 1);
if (cnt[a[l]] == need[a[l]]) -- done;
-- cnt[a[l]];
++ l;
}
}
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... |