#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 10;
int N, K, R, arr[MX], cnt[MX], req[MX];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> K >> R;
for(int i = 0; i < N; i++) cin >> arr[i];
for(int i = 0; i < R; i++){
int B, Q; cin >> B >> Q;
req[B] = Q;
}
int l = 0, r = -1, num = 0;
for(int i = 0; i < K; i++){
if(cnt[i] >= req[i]) num++;
}
int ans = 1e9 + 7;
for(; l < N && r < N; l++){
for(; num < K && r < N; ){
++r; cnt[arr[r]]++;
if(cnt[arr[r]] == req[arr[r]]) num++;
}
if(num == K){
ans = min(ans, r - l + 1);
if(cnt[arr[l]] == req[arr[l]]) num--;
cnt[arr[l]]--;
}
}
if(ans > N) cout << "impossible" << '\n';
else cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1492 KB |
Output is correct |
2 |
Correct |
12 ms |
1492 KB |
Output is correct |
3 |
Correct |
10 ms |
1524 KB |
Output is correct |
4 |
Correct |
10 ms |
1412 KB |
Output is correct |
5 |
Correct |
13 ms |
2508 KB |
Output is correct |
6 |
Correct |
9 ms |
1424 KB |
Output is correct |
7 |
Correct |
15 ms |
1624 KB |
Output is correct |
8 |
Correct |
19 ms |
3156 KB |
Output is correct |
9 |
Correct |
16 ms |
2008 KB |
Output is correct |
10 |
Correct |
11 ms |
1456 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
368 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3408 KB |
Output is correct |
2 |
Correct |
19 ms |
3184 KB |
Output is correct |
3 |
Correct |
16 ms |
2876 KB |
Output is correct |
4 |
Correct |
9 ms |
1492 KB |
Output is correct |
5 |
Correct |
22 ms |
4052 KB |
Output is correct |
6 |
Correct |
36 ms |
4664 KB |
Output is correct |
7 |
Correct |
12 ms |
2128 KB |
Output is correct |
8 |
Correct |
19 ms |
2376 KB |
Output is correct |
9 |
Correct |
9 ms |
1492 KB |
Output is correct |
10 |
Correct |
12 ms |
1488 KB |
Output is correct |
11 |
Correct |
10 ms |
1448 KB |
Output is correct |
12 |
Correct |
9 ms |
1412 KB |
Output is correct |
13 |
Correct |
13 ms |
2528 KB |
Output is correct |
14 |
Correct |
8 ms |
1492 KB |
Output is correct |
15 |
Correct |
9 ms |
1616 KB |
Output is correct |
16 |
Correct |
15 ms |
3064 KB |
Output is correct |
17 |
Correct |
12 ms |
2004 KB |
Output is correct |
18 |
Correct |
9 ms |
1496 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 |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
328 KB |
Output is correct |