#include <bits/stdc++.h>
using namespace std;
int n, k, r;
int a[200005];
int frmin[200005], fr[200005], cnt_bad;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k >> r;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= r; i++)
{
int x, y;
cin >> x >> y;
frmin[x] = y;
}
cnt_bad = r;
int dr = 0;
int ans = 1e9;
for (int i = 1; i <= n; i++)
{
while (dr < n and cnt_bad != 0)
{
dr++;
fr[a[dr]]++;
if (fr[a[dr]] == frmin[a[dr]])
cnt_bad--;
}
if (cnt_bad != 0)
break;
ans = min(ans, dr - i + 1);
fr[a[i]]--;
if (fr[a[i]] + 1 == frmin[a[i]])
cnt_bad++;
}
if (ans == (int)1e9)
cout << "impossible";
else
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1624 KB |
Output is correct |
2 |
Correct |
10 ms |
1608 KB |
Output is correct |
3 |
Correct |
9 ms |
1628 KB |
Output is correct |
4 |
Correct |
8 ms |
1552 KB |
Output is correct |
5 |
Correct |
11 ms |
2676 KB |
Output is correct |
6 |
Correct |
8 ms |
1640 KB |
Output is correct |
7 |
Correct |
14 ms |
1628 KB |
Output is correct |
8 |
Correct |
15 ms |
3276 KB |
Output is correct |
9 |
Correct |
10 ms |
2136 KB |
Output is correct |
10 |
Correct |
8 ms |
1632 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3420 KB |
Output is correct |
2 |
Correct |
17 ms |
3084 KB |
Output is correct |
3 |
Correct |
14 ms |
2932 KB |
Output is correct |
4 |
Correct |
10 ms |
1624 KB |
Output is correct |
5 |
Correct |
19 ms |
4192 KB |
Output is correct |
6 |
Correct |
23 ms |
4692 KB |
Output is correct |
7 |
Correct |
11 ms |
2140 KB |
Output is correct |
8 |
Correct |
12 ms |
2412 KB |
Output is correct |
9 |
Correct |
13 ms |
1632 KB |
Output is correct |
10 |
Correct |
8 ms |
1632 KB |
Output is correct |
11 |
Correct |
9 ms |
1684 KB |
Output is correct |
12 |
Correct |
8 ms |
1628 KB |
Output is correct |
13 |
Correct |
12 ms |
2592 KB |
Output is correct |
14 |
Correct |
7 ms |
1436 KB |
Output is correct |
15 |
Correct |
8 ms |
1628 KB |
Output is correct |
16 |
Correct |
13 ms |
3308 KB |
Output is correct |
17 |
Correct |
10 ms |
2140 KB |
Output is correct |
18 |
Correct |
8 ms |
1636 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
460 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |