이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, K, R;
cin >> N >> K >> R;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> B(K);
for (int i = 0; i < R; i++) {
int x, y;
cin >> x >> y;
B[x] = y;
}
int ans = N + 1;
int bad = R;
vector<int> freq(K);
const auto Modify = [&](int k, int sgn) {
bad -= freq[k] < B[k];
freq[k] += sgn;
bad += freq[k] < B[k];
};
for (int i = 0, j = 0; i < N; i++) {
Modify(A[i], +1);
while (bad == 0) {
Modify(A[j], -1);
if (bad == 0) {
j += 1;
} else {
Modify(A[j], +1);
break;
}
}
if (bad == 0) {
ans = min(ans, i - j + 1);
}
}
if (ans > N) {
cout << "impossible\n";
} else {
cout << ans << '\n';
}
return 0;
}
# | 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... |