This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |