#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 );
}*/
cond = k - m;
int minLen = n + 1;
for ( int l = 0; l < n; l++ ) {
for ( int r = l; r < n; r++ ) {
add( r );
if ( cond == k )
minLen = min( minLen, r - l + 1 );
}
for ( int r = l; r < n; r++ )
rem( r );
}
if ( minLen == n + 1 )
cout << "Immposible\n";
else
cout << minLen << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
2644 KB |
Output is correct |
2 |
Correct |
16 ms |
2648 KB |
Output is correct |
3 |
Correct |
17 ms |
2396 KB |
Output is correct |
4 |
Correct |
18 ms |
2396 KB |
Output is correct |
5 |
Correct |
17 ms |
2396 KB |
Output is correct |
6 |
Correct |
17 ms |
2392 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 |
10 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
2492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2037 ms |
2640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |