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 q[(int)2e5+5],cnt[(int)2e5+5],a[(int)2e5+5];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n,k,r,x,y,ans=1e9;
cin>>n>>k>>r;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<r;i++){
cin>>x>>y;
q[x]=y;
}
for(int i=0,j=0;;j++){
if(j==n)break;
if(++cnt[a[j]]==q[a[j]])r--;
if(r==0){
while(cnt[a[i]]-1>=q[a[i]]){
cnt[a[i]]--;
i++;
}
ans=min(ans,j-i+1);
}
}
if(ans==1e9)cout<<"impossible";
else cout<<ans;
}
# | 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... |