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 ALL(X) begin(X), end(X)
using namespace std;
using i64 = long long;
template <class T>
using vec = vector<T>;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, k, R; cin >> n >> k >> R;
vec<int> D(n);
for (auto& x : D) cin >> x;
vec<int> cnt(k);
vec<int> need(k);
while (R--) {
int b, q; cin >> b >> q;
need[b] = q;
}
int ans = 1e9;
for (int i = 0, r = 0, ok = 1; i < n; i++) {
if (i == 0) {
for (int b = 0; b < k; b++) {
while (r < n && cnt[b] < need[b])
cnt[D[r++]] += 1;
ok &= cnt[b] >= need[b];
}
}
else {
int b = D[i - 1];
cnt[b] -= 1;
while (r < n && cnt[b] < need[b])
cnt[D[r++]] += 1;
ok &= cnt[b] >= need[b];
}
if (!ok) break;
ans = min(ans, r - i);
}
if (ans == 1e9) cout << "impossible\n";
else cout << ans << '\n';
}
# | 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... |