#include <bits/stdc++.h>
using namespace std;
long long n, k, cnt, x, a[200010], b[200010], c[200010], l = 1, r, minn = 1e18;
int main() {
cin >> n >> k >> cnt;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= cnt; i++) {
cin >> x;
cin >> b[x];
}
while (r <= n) {
if (cnt) {
r++;
c[a[r]]++;
if (c[a[r]] == b[a[r]]) cnt--;
} else {
minn = min(minn,r-l+1);
if (c[a[l]] == b[a[l]]) cnt++;
c[a[l]]--;
l++;
}
}
if (minn == 1e18) cout << "impossible" << endl;
else cout << minn << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1780 KB |
Output is correct |
2 |
Correct |
24 ms |
1840 KB |
Output is correct |
3 |
Correct |
24 ms |
1820 KB |
Output is correct |
4 |
Correct |
23 ms |
1876 KB |
Output is correct |
5 |
Correct |
39 ms |
2456 KB |
Output is correct |
6 |
Correct |
21 ms |
1752 KB |
Output is correct |
7 |
Correct |
25 ms |
1884 KB |
Output is correct |
8 |
Correct |
41 ms |
3404 KB |
Output is correct |
9 |
Correct |
37 ms |
1856 KB |
Output is correct |
10 |
Correct |
22 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 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 |
308 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
312 KB |
Output is correct |
22 |
Correct |
0 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 |
64 ms |
2992 KB |
Output is correct |
2 |
Correct |
58 ms |
2744 KB |
Output is correct |
3 |
Correct |
57 ms |
2748 KB |
Output is correct |
4 |
Correct |
30 ms |
1768 KB |
Output is correct |
5 |
Correct |
74 ms |
3376 KB |
Output is correct |
6 |
Correct |
76 ms |
4580 KB |
Output is correct |
7 |
Correct |
37 ms |
1884 KB |
Output is correct |
8 |
Correct |
42 ms |
2176 KB |
Output is correct |
9 |
Correct |
22 ms |
1844 KB |
Output is correct |
10 |
Correct |
26 ms |
1844 KB |
Output is correct |
11 |
Correct |
30 ms |
1992 KB |
Output is correct |
12 |
Correct |
23 ms |
1876 KB |
Output is correct |
13 |
Correct |
39 ms |
2524 KB |
Output is correct |
14 |
Correct |
22 ms |
1864 KB |
Output is correct |
15 |
Correct |
26 ms |
1748 KB |
Output is correct |
16 |
Correct |
43 ms |
3396 KB |
Output is correct |
17 |
Correct |
37 ms |
1940 KB |
Output is correct |
18 |
Correct |
23 ms |
1884 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 |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
312 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
304 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
308 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |