#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N = 2e5 + 4;
int n, k, r, a[N], mn[N], cnt[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> r;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < r; ++i) {
int b;
cin >> b;
cin >> mn[b];
}
int ans = INT_MAX;
int l = 0, r = 0, ok = 0;
++cnt[a[0]];
for (int i = 0; i < k; ++i) {
if (cnt[i] >= mn[i]) {
++ok;
}
}
while (l <= r) {
if (ok == k) {
ans = min(ans, r - l + 1);
if (cnt[a[l]] == mn[a[l]]) {
--ok;
}
--cnt[a[l]];
++l;
}
else {
if (r == n - 1) {
break;
}
++r;
if (cnt[a[r]] == mn[a[r]] - 1) {
++ok;
}
++cnt[a[r]];
}
}
if (ans == INT_MAX) {
cout << "impossible";
}
else {
cout << ans;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2908 KB |
Output is correct |
2 |
Correct |
11 ms |
2904 KB |
Output is correct |
3 |
Correct |
12 ms |
3064 KB |
Output is correct |
4 |
Correct |
9 ms |
2908 KB |
Output is correct |
5 |
Correct |
14 ms |
3908 KB |
Output is correct |
6 |
Correct |
9 ms |
2892 KB |
Output is correct |
7 |
Correct |
12 ms |
3136 KB |
Output is correct |
8 |
Correct |
16 ms |
3924 KB |
Output is correct |
9 |
Correct |
14 ms |
3420 KB |
Output is correct |
10 |
Correct |
11 ms |
2912 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2524 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2512 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4176 KB |
Output is correct |
2 |
Correct |
29 ms |
4308 KB |
Output is correct |
3 |
Correct |
19 ms |
3924 KB |
Output is correct |
4 |
Correct |
8 ms |
2908 KB |
Output is correct |
5 |
Correct |
22 ms |
5092 KB |
Output is correct |
6 |
Correct |
27 ms |
4692 KB |
Output is correct |
7 |
Correct |
12 ms |
3420 KB |
Output is correct |
8 |
Correct |
14 ms |
3660 KB |
Output is correct |
9 |
Correct |
9 ms |
2904 KB |
Output is correct |
10 |
Correct |
10 ms |
2904 KB |
Output is correct |
11 |
Correct |
10 ms |
2904 KB |
Output is correct |
12 |
Correct |
9 ms |
2904 KB |
Output is correct |
13 |
Correct |
12 ms |
3932 KB |
Output is correct |
14 |
Correct |
9 ms |
2908 KB |
Output is correct |
15 |
Correct |
9 ms |
3140 KB |
Output is correct |
16 |
Correct |
14 ms |
3928 KB |
Output is correct |
17 |
Correct |
12 ms |
3416 KB |
Output is correct |
18 |
Correct |
9 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2392 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2516 KB |
Output is correct |
29 |
Correct |
0 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
0 ms |
2396 KB |
Output is correct |
32 |
Correct |
0 ms |
2512 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |