#include <iostream>
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
2244 KB |
Output is correct |
2 |
Correct |
38 ms |
2252 KB |
Output is correct |
3 |
Correct |
41 ms |
2204 KB |
Output is correct |
4 |
Correct |
31 ms |
2236 KB |
Output is correct |
5 |
Correct |
49 ms |
3672 KB |
Output is correct |
6 |
Correct |
26 ms |
2260 KB |
Output is correct |
7 |
Correct |
33 ms |
2348 KB |
Output is correct |
8 |
Correct |
70 ms |
4648 KB |
Output is correct |
9 |
Correct |
49 ms |
2820 KB |
Output is correct |
10 |
Correct |
26 ms |
2256 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
320 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 |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
4760 KB |
Output is correct |
2 |
Correct |
72 ms |
4360 KB |
Output is correct |
3 |
Correct |
65 ms |
4008 KB |
Output is correct |
4 |
Correct |
31 ms |
2232 KB |
Output is correct |
5 |
Correct |
97 ms |
5492 KB |
Output is correct |
6 |
Correct |
102 ms |
6704 KB |
Output is correct |
7 |
Correct |
47 ms |
3068 KB |
Output is correct |
8 |
Correct |
56 ms |
3280 KB |
Output is correct |
9 |
Correct |
26 ms |
2232 KB |
Output is correct |
10 |
Correct |
28 ms |
2252 KB |
Output is correct |
11 |
Correct |
31 ms |
2268 KB |
Output is correct |
12 |
Correct |
28 ms |
2180 KB |
Output is correct |
13 |
Correct |
51 ms |
3596 KB |
Output is correct |
14 |
Correct |
26 ms |
2228 KB |
Output is correct |
15 |
Correct |
31 ms |
2312 KB |
Output is correct |
16 |
Correct |
64 ms |
4660 KB |
Output is correct |
17 |
Correct |
58 ms |
2900 KB |
Output is correct |
18 |
Correct |
27 ms |
2216 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 |
320 KB |
Output is correct |
22 |
Correct |
2 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
304 KB |
Output is correct |
27 |
Correct |
1 ms |
304 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
304 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |