#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int N, K, R;
cin >> N >> K >> R;
int D[N+1];
for(int i = 1; i <= N; i++) cin >> D[i];
vector<int> req(K, 0);
vector<int> act(K, 0);
int a, r, b;
for(int i = 1; i <= R; i++)
{
cin >> a >> r;
req[a] = r;
}
a = 1;
int g = 0;
int res = 2000000000;
for(int i = 0; i < K; i++) g += req[i] == 0;
for(b = 1; b <= N && g < K; b++)
{
act[D[b]]++;
if(req[D[b]] == act[D[b]]) g++;
}
b--;
if(g == K) res = b;
for(int a = 2; a <= N; a++)
{
act[D[a-1]]--;
if(act[D[a-1]] == req[D[a-1]] - 1) g--;
for(b++; b <= N && g < K; b++)
{
act[D[b]]++;
if(req[D[b]] == act[D[b]]) g++;
}
b--;
if(g == K) res = min(res, b-a+1);
}
if(res == 2000000000) cout << "impossible\n";
else cout << res << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
1516 KB |
Output is correct |
2 |
Correct |
38 ms |
1516 KB |
Output is correct |
3 |
Correct |
38 ms |
1516 KB |
Output is correct |
4 |
Correct |
42 ms |
1560 KB |
Output is correct |
5 |
Correct |
62 ms |
2924 KB |
Output is correct |
6 |
Correct |
35 ms |
1516 KB |
Output is correct |
7 |
Correct |
40 ms |
1644 KB |
Output is correct |
8 |
Correct |
66 ms |
3948 KB |
Output is correct |
9 |
Correct |
55 ms |
2156 KB |
Output is correct |
10 |
Correct |
36 ms |
1516 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
276 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
3436 KB |
Output is correct |
2 |
Correct |
91 ms |
3180 KB |
Output is correct |
3 |
Correct |
74 ms |
2924 KB |
Output is correct |
4 |
Correct |
37 ms |
1516 KB |
Output is correct |
5 |
Correct |
113 ms |
4076 KB |
Output is correct |
6 |
Correct |
116 ms |
4588 KB |
Output is correct |
7 |
Correct |
58 ms |
2156 KB |
Output is correct |
8 |
Correct |
65 ms |
2412 KB |
Output is correct |
9 |
Correct |
35 ms |
1516 KB |
Output is correct |
10 |
Correct |
38 ms |
1516 KB |
Output is correct |
11 |
Correct |
38 ms |
1516 KB |
Output is correct |
12 |
Correct |
37 ms |
1516 KB |
Output is correct |
13 |
Correct |
64 ms |
3052 KB |
Output is correct |
14 |
Correct |
35 ms |
1516 KB |
Output is correct |
15 |
Correct |
42 ms |
1644 KB |
Output is correct |
16 |
Correct |
66 ms |
3948 KB |
Output is correct |
17 |
Correct |
54 ms |
2156 KB |
Output is correct |
18 |
Correct |
35 ms |
1516 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |