#include <bits/stdc++.h>
int main() {
int N, K, R;
std::cin >> N >> K >> R;
std::vector<int> D(N);
for (auto &e : D) {
std::cin >> e;
}
std::vector<std::vector<int>> index_list(K);
for (int i = 0; i < N; ++i) {
index_list[D[i]].push_back(i);
}
std::vector<std::vector<std::pair<int, bool>>> events(N + 1);
while (R--) {
int B, Q;
std::cin >> B >> Q;
const auto &list = index_list[B];
if ((int)list.size() < Q) {
events[0].push_back({3 * N, true});
break;
}
events[0].push_back({list[Q - 1], true});
for (int i = 0; i < (int)list.size() - Q; ++i) {
events[list[i] + 1].push_back({list[i + Q - 1], false});
events[list[i] + 1].push_back({list[i + Q], true});
}
events[list[(int)list.size() - Q] + 1].push_back({3 * N, true});
}
std::multiset<int> mls;
int answer = N + 1;
for (int i = 0; i < N; ++i) {
for (const auto &[v, b] : events[i]) {
if (b) {
mls.insert(v);
} else {
mls.erase(mls.find(v));
}
}
answer = std::min(answer, *mls.rbegin() - i + 1);
}
if (answer == N + 1) {
std::cout << "impossible" << std::endl;
} else {
std::cout << answer << std::endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
9492 KB |
Output is correct |
2 |
Correct |
46 ms |
10304 KB |
Output is correct |
3 |
Correct |
54 ms |
11576 KB |
Output is correct |
4 |
Correct |
46 ms |
10516 KB |
Output is correct |
5 |
Correct |
65 ms |
10284 KB |
Output is correct |
6 |
Correct |
30 ms |
6832 KB |
Output is correct |
7 |
Correct |
35 ms |
7268 KB |
Output is correct |
8 |
Correct |
78 ms |
17964 KB |
Output is correct |
9 |
Correct |
53 ms |
8268 KB |
Output is correct |
10 |
Correct |
50 ms |
11016 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
560 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
304 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
256 KB |
Output is correct |
23 |
Correct |
0 ms |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
300 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
24512 KB |
Output is correct |
2 |
Correct |
193 ms |
20780 KB |
Output is correct |
3 |
Correct |
98 ms |
13000 KB |
Output is correct |
4 |
Correct |
52 ms |
12200 KB |
Output is correct |
5 |
Correct |
66 ms |
11212 KB |
Output is correct |
6 |
Correct |
199 ms |
29320 KB |
Output is correct |
7 |
Correct |
108 ms |
11568 KB |
Output is correct |
8 |
Correct |
128 ms |
13504 KB |
Output is correct |
9 |
Correct |
42 ms |
9448 KB |
Output is correct |
10 |
Correct |
45 ms |
10304 KB |
Output is correct |
11 |
Correct |
54 ms |
11580 KB |
Output is correct |
12 |
Correct |
48 ms |
10528 KB |
Output is correct |
13 |
Correct |
72 ms |
10284 KB |
Output is correct |
14 |
Correct |
29 ms |
6852 KB |
Output is correct |
15 |
Correct |
36 ms |
7372 KB |
Output is correct |
16 |
Correct |
89 ms |
17920 KB |
Output is correct |
17 |
Correct |
64 ms |
8236 KB |
Output is correct |
18 |
Correct |
52 ms |
11092 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
568 KB |
Output is correct |
22 |
Correct |
2 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 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 |
300 KB |
Output is correct |
29 |
Correct |
0 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 |
1 ms |
304 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |