#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5;
const int MAX_K = MAX_N;
int v[MAX_N], f[MAX_K], q[MAX_K];
int cond;
void add( int i ) {
f[v[i]]++;
if ( f[v[i]] == q[v[i]] )
cond++;
}
void rem( int i ) {
if ( f[v[i]] == q[v[i]] )
cond--;
f[v[i]]--;
}
int main() {
int n, k, m;
cin >> n >> k >> m;
for ( int i = 0; i < n; i++ )
cin >> v[i];
for ( int i = 0; i < m; i++ ) {
int b;
cin >> b;
cin >> q[b];
}
cond = k - m;
int l = 0, minLen = n + 1;
for ( int r = 0; r < n; r++ ) {
add( r );
while ( cond >= k && l <= r ) {
rem( l );
l++;
}
if ( l > 0 ) {
l--;
add( l );
}
if ( cond >= k )
minLen = min( minLen, r - l + 1 );
}
if ( minLen == n + 1 )
cout << "impossible\n";
else
cout << minLen << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2420 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2396 KB |
Output is correct |
2 |
Correct |
24 ms |
2532 KB |
Output is correct |
3 |
Correct |
23 ms |
2396 KB |
Output is correct |
4 |
Correct |
22 ms |
2396 KB |
Output is correct |
5 |
Correct |
41 ms |
2528 KB |
Output is correct |
6 |
Correct |
22 ms |
2396 KB |
Output is correct |
7 |
Correct |
25 ms |
2396 KB |
Output is correct |
8 |
Correct |
41 ms |
3832 KB |
Output is correct |
9 |
Correct |
35 ms |
3420 KB |
Output is correct |
10 |
Correct |
22 ms |
2900 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
2 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2400 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2404 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
2736 KB |
Output is correct |
2 |
Correct |
60 ms |
2988 KB |
Output is correct |
3 |
Correct |
45 ms |
2648 KB |
Output is correct |
4 |
Correct |
23 ms |
2396 KB |
Output is correct |
5 |
Correct |
69 ms |
2764 KB |
Output is correct |
6 |
Correct |
72 ms |
4692 KB |
Output is correct |
7 |
Correct |
36 ms |
3408 KB |
Output is correct |
8 |
Correct |
41 ms |
3676 KB |
Output is correct |
9 |
Correct |
22 ms |
2908 KB |
Output is correct |
10 |
Correct |
22 ms |
2888 KB |
Output is correct |
11 |
Correct |
24 ms |
2908 KB |
Output is correct |
12 |
Correct |
22 ms |
3008 KB |
Output is correct |
13 |
Correct |
39 ms |
3664 KB |
Output is correct |
14 |
Correct |
21 ms |
2896 KB |
Output is correct |
15 |
Correct |
25 ms |
2976 KB |
Output is correct |
16 |
Correct |
43 ms |
3920 KB |
Output is correct |
17 |
Correct |
35 ms |
3412 KB |
Output is correct |
18 |
Correct |
22 ms |
2900 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2488 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |