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 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';
}
# | 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... |