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 maxn = 2e5 + 5;
#define pii pair<int, int>
#define ll long long
int v[maxn], need[maxn];
map<int, int> mp;
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 a, b; cin >> a >> b;
need[a] = b;
}
int l = 0, r = 0;
int ans = n+1, invalid_cnt = m;
while(l<n){
bool term = false;
while(invalid_cnt){
if(r==n) {term = true; break;}
mp[v[r]]++;
if(mp[v[r]]==need[v[r]]) invalid_cnt--;
r++;
}
if(term==true) break;
while(true){
if(mp[v[l]]==need[v[l]]) break;
mp[v[l]]--;
l++;
}
ans = min(ans, r-l);
mp[v[l]]--, invalid_cnt++, l++;
}
if(ans == n+1) 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... |