#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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1628 KB |
Output is correct |
2 |
Correct |
7 ms |
1628 KB |
Output is correct |
3 |
Correct |
8 ms |
1628 KB |
Output is correct |
4 |
Correct |
10 ms |
1620 KB |
Output is correct |
5 |
Correct |
12 ms |
2908 KB |
Output is correct |
6 |
Correct |
6 ms |
1628 KB |
Output is correct |
7 |
Correct |
7 ms |
1628 KB |
Output is correct |
8 |
Correct |
11 ms |
3932 KB |
Output is correct |
9 |
Correct |
8 ms |
2204 KB |
Output is correct |
10 |
Correct |
7 ms |
1628 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
456 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
452 KB |
Output is correct |
24 |
Correct |
0 ms |
460 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3420 KB |
Output is correct |
2 |
Correct |
13 ms |
3320 KB |
Output is correct |
3 |
Correct |
12 ms |
2908 KB |
Output is correct |
4 |
Correct |
8 ms |
1624 KB |
Output is correct |
5 |
Correct |
16 ms |
4440 KB |
Output is correct |
6 |
Correct |
18 ms |
4700 KB |
Output is correct |
7 |
Correct |
9 ms |
2260 KB |
Output is correct |
8 |
Correct |
10 ms |
2388 KB |
Output is correct |
9 |
Correct |
6 ms |
1496 KB |
Output is correct |
10 |
Correct |
7 ms |
1620 KB |
Output is correct |
11 |
Correct |
8 ms |
1624 KB |
Output is correct |
12 |
Correct |
7 ms |
1628 KB |
Output is correct |
13 |
Correct |
9 ms |
3032 KB |
Output is correct |
14 |
Correct |
6 ms |
1628 KB |
Output is correct |
15 |
Correct |
7 ms |
1628 KB |
Output is correct |
16 |
Correct |
12 ms |
3920 KB |
Output is correct |
17 |
Correct |
9 ms |
2140 KB |
Output is correct |
18 |
Correct |
6 ms |
1628 KB |
Output is correct |
19 |
Correct |
0 ms |
460 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |