#include<bits/stdc++.h>
using namespace std;
int n , k , r;
int main(){
cin >> n >> k >> r;
vector<int> a(n + 1) , have(k) , want(k);
for(int i = 1;i <= n;i ++){
cin >> a[i];
}
int is_good = 0;
for(int i = 1;i <= r;i ++){
int B , Q;
cin >> B >> Q;
want[B] = Q;
}
int ans = 1e9 , l = 1;
for(int i = 1;i <= n;i ++){
++have[a[i]];
is_good += have[a[i]] == want[a[i]];
while(have[a[l]] - 1 >= want[a[l]] && l <= i){
--have[a[l]];
++l;
}
if(is_good == r){
ans = min(ans , i - l + 1);
}
}
if(ans == 1e9){
cout << "impossible" << endl;
return 0;
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
412 KB |
Output is correct |
6 |
Correct |
1 ms |
500 KB |
Output is correct |
7 |
Correct |
1 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 |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1628 KB |
Output is correct |
2 |
Correct |
27 ms |
1364 KB |
Output is correct |
3 |
Correct |
25 ms |
1624 KB |
Output is correct |
4 |
Correct |
24 ms |
1628 KB |
Output is correct |
5 |
Correct |
49 ms |
2988 KB |
Output is correct |
6 |
Correct |
24 ms |
1628 KB |
Output is correct |
7 |
Correct |
27 ms |
1628 KB |
Output is correct |
8 |
Correct |
42 ms |
4024 KB |
Output is correct |
9 |
Correct |
36 ms |
2232 KB |
Output is correct |
10 |
Correct |
23 ms |
1372 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
1 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 |
0 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 |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
3492 KB |
Output is correct |
2 |
Correct |
59 ms |
3072 KB |
Output is correct |
3 |
Correct |
65 ms |
3156 KB |
Output is correct |
4 |
Correct |
24 ms |
1372 KB |
Output is correct |
5 |
Correct |
74 ms |
4032 KB |
Output is correct |
6 |
Correct |
75 ms |
4652 KB |
Output is correct |
7 |
Correct |
43 ms |
2132 KB |
Output is correct |
8 |
Correct |
43 ms |
2516 KB |
Output is correct |
9 |
Correct |
23 ms |
1372 KB |
Output is correct |
10 |
Correct |
24 ms |
1368 KB |
Output is correct |
11 |
Correct |
25 ms |
1628 KB |
Output is correct |
12 |
Correct |
24 ms |
1624 KB |
Output is correct |
13 |
Correct |
42 ms |
3152 KB |
Output is correct |
14 |
Correct |
23 ms |
1368 KB |
Output is correct |
15 |
Correct |
34 ms |
1780 KB |
Output is correct |
16 |
Correct |
44 ms |
3928 KB |
Output is correct |
17 |
Correct |
36 ms |
2136 KB |
Output is correct |
18 |
Correct |
23 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
356 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
436 KB |
Output is correct |
27 |
Correct |
0 ms |
352 KB |
Output is correct |
28 |
Correct |
0 ms |
436 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
344 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 |