#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 << "Immposible\n";
else
cout << minLen << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2500 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 |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
1 ms |
2496 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
2940 KB |
Output is correct |
2 |
Correct |
26 ms |
2908 KB |
Output is correct |
3 |
Correct |
27 ms |
2988 KB |
Output is correct |
4 |
Correct |
22 ms |
2908 KB |
Output is correct |
5 |
Correct |
45 ms |
3876 KB |
Output is correct |
6 |
Correct |
21 ms |
2904 KB |
Output is correct |
7 |
Incorrect |
35 ms |
2896 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
4520 KB |
Output is correct |
2 |
Correct |
60 ms |
4252 KB |
Output is correct |
3 |
Correct |
49 ms |
4128 KB |
Output is correct |
4 |
Correct |
23 ms |
2992 KB |
Output is correct |
5 |
Incorrect |
79 ms |
4756 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |