#include <bits/stdc++.h>
using namespace std;
const int N = (int) 2e5 + 7;
const int INF = (int) 1e9 + 7;
int n;
int k;
int r;
int base[N];
int min_quantity[N];
int f[N];
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
///freopen ("input.txt", "r", stdin);
cin >> n >> k >> r;
for (int i = 0; i < n; i++) {
cin >> base[i];
}
for (int i = 0; i < r; i++) {
int base_id;
cin >> base_id;
cin >> min_quantity[base_id];
}
int unsolved_restrictions = r;
int l = 0, sol = INF;
for (int r = 0; r < n; r++) {
f[base[r]]++;
unsolved_restrictions -= (min_quantity[base[r]] > 0 && f[base[r]] == min_quantity[base[r]]);
if (unsolved_restrictions == 0) {
while (min_quantity[base[l]] == 0 || f[base[l]] != min_quantity[base[l]]) {
f[base[l++]]--;
}
sol = min(sol, r - l + 1);
}
}
if (sol == INF) {
cout << "impossible\n";
return 0;
}
cout << sol << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1108 KB |
Output is correct |
2 |
Correct |
11 ms |
1004 KB |
Output is correct |
3 |
Correct |
12 ms |
1108 KB |
Output is correct |
4 |
Correct |
11 ms |
1108 KB |
Output is correct |
5 |
Correct |
15 ms |
1352 KB |
Output is correct |
6 |
Correct |
10 ms |
1108 KB |
Output is correct |
7 |
Correct |
12 ms |
1108 KB |
Output is correct |
8 |
Correct |
19 ms |
1876 KB |
Output is correct |
9 |
Correct |
19 ms |
1108 KB |
Output is correct |
10 |
Correct |
11 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 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 |
0 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 |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1612 KB |
Output is correct |
2 |
Correct |
21 ms |
1488 KB |
Output is correct |
3 |
Correct |
18 ms |
1540 KB |
Output is correct |
4 |
Correct |
15 ms |
1108 KB |
Output is correct |
5 |
Correct |
26 ms |
1768 KB |
Output is correct |
6 |
Correct |
28 ms |
2448 KB |
Output is correct |
7 |
Correct |
14 ms |
1120 KB |
Output is correct |
8 |
Correct |
19 ms |
1172 KB |
Output is correct |
9 |
Correct |
10 ms |
1108 KB |
Output is correct |
10 |
Correct |
11 ms |
1108 KB |
Output is correct |
11 |
Correct |
12 ms |
1072 KB |
Output is correct |
12 |
Correct |
13 ms |
1116 KB |
Output is correct |
13 |
Correct |
16 ms |
1412 KB |
Output is correct |
14 |
Correct |
11 ms |
1012 KB |
Output is correct |
15 |
Correct |
11 ms |
1108 KB |
Output is correct |
16 |
Correct |
19 ms |
1908 KB |
Output is correct |
17 |
Correct |
14 ms |
1108 KB |
Output is correct |
18 |
Correct |
11 ms |
1092 KB |
Output is correct |
19 |
Correct |
1 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |