이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9;
int main() {
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k, m, ans = inf;
cin >> n >> k >> m;
vector<int> a(n), need(k), have(k);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) {
int x, c;
cin >> x >> c;
need[x] = c;
}
int cnt = k - m;
for (int l = 0, r = 0; r < n; r++) {
if (have[a[r]] >= need[a[r]]) cnt--;
have[a[r]]++;
if (have[a[r]] >= need[a[r]]) cnt++;
if (cnt != k) continue;
while (cnt == k) {
if (have[a[l]] >= need[a[l]]) cnt--;
have[a[l]]--;
if (have[a[l]] >= need[a[l]]) cnt++;
l++;
}
ans = min(ans, r - l + 2);
}
if (ans == inf) 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... |