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 endl '\n'
#define pb push_back
#define ll long long
#define int long long
const long long inf=1e18;
const int MOD=998244353;
const int N=3e5+5;
int req[N],am[N];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,k,r; cin>>n>>k>>r;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
set<int> bad;
for(int i=0;i<r;i++){
int x,y; cin>>x>>y;
bad.insert(x);
req[x]=y;
}
int ans=inf,l=0;
for(int i=0;i<n;i++){
am[a[i]]++;
if(am[a[i]]==req[a[i]]){
bad.erase(a[i]);
}
while(bad.size()==0){
if(am[a[l]]<=req[a[l]])break;
am[a[l]]--;
l++;
}
if(bad.size()==0){
ans=min(ans,i-l+1);
}
}
if(ans==inf)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... |