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;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k, r; cin >> n >> k >> r;
vector<int>a(n + 1), req(n + 1), freq(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= r; i++){
int x, y; cin >> x >> y;
req[x] = y;
}
int ans = 1e9;
int left = 1, right = 0;
int ok = 0;
while(left <= n && right <= n){
while(right + 1 <= n && ok != r){
freq[a[right + 1]]++;
if(freq[a[right + 1]] == req[a[right + 1]]) ok++;
right++;
}
if(ok != r) break;
ans = min(ans, right - left + 1);
freq[a[left]]--;
if(freq[a[left]] < req[a[left]]) ok--;
left++;
}
if(ans == 1e9) cout << "impossible" << '\n';
else cout << ans << '\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... |