#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, K, R;
cin >> N >> K >> R;
vector<int> D(N);
for (int &v : D) {
cin >> v;
}
vector<int> cnt(N);
multiset<int> S;
for (int i = 0; i < R; i++) {
int B;
cin >> B;
cin >> cnt[B];
}
for (int i = 0; i < N; i++) {
S.insert(cnt[i]);
}
int ans = N + 1;
for (int i = 0, j = 0; i < N; i++) {
j = max(j, i);
while (j < N && *S.rbegin() > 0) {
S.erase(S.find(cnt[D[j]]));
S.insert(--cnt[D[j]]);
j++;
}
if (*S.rbegin() <= 0) {
ans = min(ans, j - i);
}
S.erase(S.find(cnt[D[i]]));
S.insert(++cnt[D[i]]);
}
if (ans > N) {
cout << "impossible\n";
} else {
cout << ans << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
452 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 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 |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
316 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
11668 KB |
Output is correct |
2 |
Correct |
125 ms |
11660 KB |
Output is correct |
3 |
Correct |
113 ms |
11632 KB |
Output is correct |
4 |
Correct |
118 ms |
11688 KB |
Output is correct |
5 |
Correct |
114 ms |
12348 KB |
Output is correct |
6 |
Correct |
138 ms |
11724 KB |
Output is correct |
7 |
Correct |
118 ms |
11848 KB |
Output is correct |
8 |
Correct |
124 ms |
12540 KB |
Output is correct |
9 |
Correct |
108 ms |
12108 KB |
Output is correct |
10 |
Correct |
113 ms |
11680 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
316 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
12712 KB |
Output is correct |
2 |
Correct |
124 ms |
12816 KB |
Output is correct |
3 |
Correct |
107 ms |
12484 KB |
Output is correct |
4 |
Correct |
123 ms |
11664 KB |
Output is correct |
5 |
Correct |
193 ms |
12812 KB |
Output is correct |
6 |
Correct |
120 ms |
12748 KB |
Output is correct |
7 |
Correct |
136 ms |
12280 KB |
Output is correct |
8 |
Correct |
129 ms |
12376 KB |
Output is correct |
9 |
Correct |
119 ms |
11576 KB |
Output is correct |
10 |
Correct |
117 ms |
11592 KB |
Output is correct |
11 |
Correct |
113 ms |
11708 KB |
Output is correct |
12 |
Correct |
116 ms |
11680 KB |
Output is correct |
13 |
Correct |
115 ms |
12420 KB |
Output is correct |
14 |
Correct |
139 ms |
11604 KB |
Output is correct |
15 |
Correct |
117 ms |
11840 KB |
Output is correct |
16 |
Correct |
127 ms |
12544 KB |
Output is correct |
17 |
Correct |
111 ms |
12208 KB |
Output is correct |
18 |
Correct |
113 ms |
11604 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
448 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
316 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |