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;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, K, R;
cin >> N >> K >> R;
vector<int> D(N);
for (int &v : D) {
cin >> v;
}
vector<int> cnt(N);
multiset<int> S;
for (int i = 0; i < R; i++) {
int B;
cin >> B;
cin >> cnt[B];
}
for (int i = 0; i < N; i++) {
S.insert(cnt[i]);
}
int ans = N + 1;
for (int i = 0, j = 0; i < N; i++) {
j = max(j, i);
while (j < N && *S.rbegin() > 0) {
S.erase(S.find(cnt[D[j]]));
S.insert(--cnt[D[j]]);
j++;
}
if (*S.rbegin() <= 0) {
ans = min(ans, j - i);
}
S.erase(S.find(cnt[D[i]]));
S.insert(++cnt[D[i]]);
}
if (ans > N) {
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... |