/**
* author: wxhtzdy
* created: 10.11.2022 15:50:40
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
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> need(k, -1);
for (int i = 0; i < n; i++) {
int b, q;
cin >> b >> q;
need[b] = q;
}
int cnt_good = 0;
vector<int> cnt(k);
int ptr = -1;
int ans = n + 1;
auto Add = [&](int x) {
cnt[x] += 1;
if (cnt[x] == need[x]) {
cnt_good += 1;
}
};
auto Remove = [&](int x) {
if (cnt[x] == need[x]) {
cnt_good -= 1;
}
cnt[x] -= 1;
};
for (int i = 0; i < n; i++) {
while (ptr + 1 < n && cnt_good < r) {
ptr += 1;
Add(a[ptr]);
}
if (cnt_good == r) {
ans = min(ans, ptr - i + 1);
}
Remove(a[i]);
}
if (ans > n) {
cout << "impossible" << '\n';
} else {
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1492 KB |
Output is correct |
2 |
Correct |
14 ms |
1484 KB |
Output is correct |
3 |
Correct |
15 ms |
1492 KB |
Output is correct |
4 |
Correct |
17 ms |
1492 KB |
Output is correct |
5 |
Correct |
20 ms |
2884 KB |
Output is correct |
6 |
Correct |
14 ms |
1484 KB |
Output is correct |
7 |
Correct |
17 ms |
1616 KB |
Output is correct |
8 |
Correct |
21 ms |
3924 KB |
Output is correct |
9 |
Correct |
19 ms |
2120 KB |
Output is correct |
10 |
Correct |
15 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3396 KB |
Output is correct |
2 |
Correct |
29 ms |
3124 KB |
Output is correct |
3 |
Correct |
22 ms |
2748 KB |
Output is correct |
4 |
Correct |
16 ms |
1492 KB |
Output is correct |
5 |
Correct |
31 ms |
4024 KB |
Output is correct |
6 |
Correct |
34 ms |
4540 KB |
Output is correct |
7 |
Correct |
19 ms |
2160 KB |
Output is correct |
8 |
Correct |
22 ms |
2356 KB |
Output is correct |
9 |
Correct |
17 ms |
1492 KB |
Output is correct |
10 |
Correct |
15 ms |
1492 KB |
Output is correct |
11 |
Correct |
16 ms |
1492 KB |
Output is correct |
12 |
Correct |
15 ms |
1480 KB |
Output is correct |
13 |
Correct |
22 ms |
2884 KB |
Output is correct |
14 |
Correct |
14 ms |
1480 KB |
Output is correct |
15 |
Correct |
15 ms |
1612 KB |
Output is correct |
16 |
Correct |
21 ms |
3908 KB |
Output is correct |
17 |
Correct |
20 ms |
2056 KB |
Output is correct |
18 |
Correct |
15 ms |
1476 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
320 KB |
Output is correct |