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;
#define int long long
int n;int K;int m;
int ar[1000006];
int freq[1000006];
int isin[1000006];
int nd[1000006];
int ans;
int tot;
void ad(int v){
freq[v]++;
if(isin[v]&&nd[v]==freq[v]){
tot++;
}
}
void del(int v){
if(isin[v]&&nd[v]==freq[v]){
tot--;
}
freq[v]--;
}
signed main() {
cin>>n>>K>>m;
for(int i=1;i<=n;i++){
cin>>ar[i];
}
for(int i=1;i<=m;i++){
int pl;int v;
cin>>pl>>v;
isin[pl]=1;
nd[pl]=v;
}
ans=n+1;
tot=0;
int rit=0;
for(int i=1;i<=n;i++){
while(tot<m&&rit<=n-1){ad(ar[++rit]);}
if(tot==m){
ans=min(ans,rit-i+1);
}
// cout<<i<<" "<<rit<<" "<<tot<<endl;
del(ar[i]);
}
if(ans==n+1){
cout<<"impossible\n";return 0;
}
cout<<ans<<endl;
}
# | 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... |