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 MN=2e5+2;
int N,K,R,d[MN],req[MN],f[MN];
int main() {
ios::sync_with_stdio(0);cin.tie(0);
cin>>N>>K>>R;
for(int i=1;i<=N;++i) cin>>d[i];
set<int> needs;
for(int i=1;i<=R;++i) {
int b,q;
cin>>b>>q;
req[b]=q;
needs.insert(b);
}
int l=1,r=1;
for(;r<=N;++r) {
if(needs.empty()) break;
if(++f[d[r]]==req[d[r]]) needs.erase(d[r]);
}
if(r>N&&needs.size()) {
cout<<"impossible\n";
return 0;
}
int ans=r-l;
for(;l<=N;++l) {
--f[d[l]];
while(f[d[l]]<req[d[l]]) {
if(r>N) {
cout<<ans<<'\n';
return 0;
}
++f[d[r]];
++r;
}
ans=min(ans,r-l-1);
}
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... |