#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int n, k;
cin>>n >> k;
int m;
cin>>m;
vector<int> req(k + 1, 0);
vector<int>v;
for(int i=0; i<n; i++){
int a;
cin>>a;
v.push_back(a);
}
for(int j=0; j<m; j++){
int a, b;
cin>>a>>b;
req[a] = b;
}
int min_length=2e9;
int tmp = m;
int j = 0;
for(int i = 0; i < n; i++) {
while(tmp > 0 and j < n) {
req[v[j]]--;
if(req[v[j]] == 0) {
tmp--;
}
j++;
}
if(tmp == 0) {
min_length = min(min_length, j - i);
}
req[v[i]]++;
if(req[v[i]] > 0) {
tmp++;
}
}
if(min_length == 2e9) {
cout << "impossible";
}
else
cout << min_length << endl;
return 0;
}
/*
5 2 2
0 1 1 0 1
0 1
1 1
13 4 3
1 1 3 2 0 1 2 0 0 0 0 3 1
0 2
2 1
1 2
5 3 1
1 2 0 1 2
0 2
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
224 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
320 KB |
Output is correct |
11 |
Correct |
0 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 |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1748 KB |
Output is correct |
2 |
Correct |
14 ms |
1876 KB |
Output is correct |
3 |
Correct |
15 ms |
1872 KB |
Output is correct |
4 |
Correct |
13 ms |
1836 KB |
Output is correct |
5 |
Correct |
20 ms |
2796 KB |
Output is correct |
6 |
Correct |
13 ms |
1876 KB |
Output is correct |
7 |
Correct |
14 ms |
1996 KB |
Output is correct |
8 |
Correct |
22 ms |
3188 KB |
Output is correct |
9 |
Correct |
17 ms |
2376 KB |
Output is correct |
10 |
Correct |
13 ms |
1872 KB |
Output is correct |
11 |
Correct |
1 ms |
320 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 |
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 |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 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 |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
3268 KB |
Output is correct |
2 |
Correct |
31 ms |
3012 KB |
Output is correct |
3 |
Correct |
22 ms |
2764 KB |
Output is correct |
4 |
Correct |
14 ms |
1876 KB |
Output is correct |
5 |
Correct |
40 ms |
3656 KB |
Output is correct |
6 |
Correct |
35 ms |
4012 KB |
Output is correct |
7 |
Correct |
18 ms |
2316 KB |
Output is correct |
8 |
Correct |
20 ms |
2368 KB |
Output is correct |
9 |
Correct |
14 ms |
1876 KB |
Output is correct |
10 |
Correct |
14 ms |
1864 KB |
Output is correct |
11 |
Correct |
15 ms |
1868 KB |
Output is correct |
12 |
Correct |
14 ms |
1872 KB |
Output is correct |
13 |
Correct |
18 ms |
2804 KB |
Output is correct |
14 |
Correct |
13 ms |
1868 KB |
Output is correct |
15 |
Correct |
14 ms |
2000 KB |
Output is correct |
16 |
Correct |
28 ms |
3264 KB |
Output is correct |
17 |
Correct |
21 ms |
2260 KB |
Output is correct |
18 |
Correct |
13 ms |
1776 KB |
Output is correct |
19 |
Correct |
1 ms |
320 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 |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
320 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |