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 ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n,k,r;
cin>>n>>k>>r;
int a[n];
set<int>st[k];
for(int i=0;i<k;i++){
st[i].insert(n);
}
for(int i=0;i<n;i++){
cin>>a[i];
st[a[i]].insert(i);
}
vector<bool>need(k,0);
int b[r],q[r];
bool ok=true;
int R=0;
for(int i=0;i<r;i++){
cin>>b[i]>>q[i];
need[b[i]]=true;
if((int)st[b[i]].size()-1<q[i]){
cout<<"impossible";
return 0;
}
q[i]--;
R=max(R,*st[b[i]].begin());
while(q[i]--){
st[b[i]].erase(st[b[i]].begin());
R=max(R,*st[b[i]].begin());
}
}
int ans=n;
for(int i=0;i<n;i++){
if(R<n) ans=min(ans,R-i+1);
if(need[a[i]]==true){
st[a[i]].erase(st[a[i]].begin());
if(!st[a[i]].empty()){
R=max(R,*st[a[i]].begin());
}
}
}
cout<<ans;
}
Compilation message (stderr)
dna.cpp: In function 'int main()':
dna.cpp:27:10: warning: unused variable 'ok' [-Wunused-variable]
27 | bool ok=true;
| ^~
# | 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... |