#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 |
2392 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2512 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 |
2396 KB |
Output is correct |
3 |
Correct |
1 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 |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2512 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2888 KB |
Output is correct |
2 |
Correct |
9 ms |
2904 KB |
Output is correct |
3 |
Correct |
10 ms |
2908 KB |
Output is correct |
4 |
Correct |
9 ms |
2924 KB |
Output is correct |
5 |
Correct |
13 ms |
4188 KB |
Output is correct |
6 |
Correct |
8 ms |
2776 KB |
Output is correct |
7 |
Correct |
9 ms |
3164 KB |
Output is correct |
8 |
Correct |
14 ms |
3932 KB |
Output is correct |
9 |
Correct |
11 ms |
3420 KB |
Output is correct |
10 |
Correct |
9 ms |
3008 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 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 |
0 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2516 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4444 KB |
Output is correct |
2 |
Correct |
18 ms |
4280 KB |
Output is correct |
3 |
Correct |
15 ms |
3932 KB |
Output is correct |
4 |
Correct |
8 ms |
2908 KB |
Output is correct |
5 |
Correct |
22 ms |
4780 KB |
Output is correct |
6 |
Correct |
25 ms |
4692 KB |
Output is correct |
7 |
Correct |
12 ms |
3420 KB |
Output is correct |
8 |
Correct |
14 ms |
3808 KB |
Output is correct |
9 |
Correct |
8 ms |
2908 KB |
Output is correct |
10 |
Correct |
9 ms |
2904 KB |
Output is correct |
11 |
Correct |
10 ms |
2908 KB |
Output is correct |
12 |
Correct |
9 ms |
2908 KB |
Output is correct |
13 |
Correct |
12 ms |
3912 KB |
Output is correct |
14 |
Correct |
8 ms |
2904 KB |
Output is correct |
15 |
Correct |
9 ms |
3160 KB |
Output is correct |
16 |
Correct |
15 ms |
3932 KB |
Output is correct |
17 |
Correct |
11 ms |
3420 KB |
Output is correct |
18 |
Correct |
8 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2528 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
0 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
0 ms |
2396 KB |
Output is correct |
33 |
Correct |
0 ms |
2396 KB |
Output is correct |