Submission #1156609

#TimeUsernameProblemLanguageResultExecution timeMemory
1156609the_ZHER Martian DNA (BOI18_dna)C++20
0 / 100
48 ms3252 KiB
#include <bits/stdc++.h> #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long using namespace std; const int inf=1e17; const int N=2e5+5; const int N1=1e5+5; const int N2=5e6+6; const int mod=1e9+7; const int k1=447; struct edge{ int d,in; }; struct edge1{ int l,r; }; vector<int>v; int dp[N]; int dp1[N]; signed main(){ int n,k,q; cin>>n>>k>>q; v.push_back(0); for(int i=1;i<=n;i++){ int x; cin>>x; dp[x]++; v.push_back(x); } int ok=0; for(int i=1;i<=q;i++){ int x,cnt; cin>>x>>cnt; dp1[x]=max(dp1[x],cnt); if(dp[x]<cnt){ ok=1; } } if(ok==1){ cout<<"impossible"; return 0; } int l=1,r=n; int ans=n; while(l<r){ int ok1=0; if(dp[v[l]]-1>=dp1[v[l]]){ dp[v[l]]--; l++; ok1=1; } if(dp[v[r]]-1>=dp1[v[r]]){ dp[v[r]]--; r--; ok1=1; } if(ok1==0){ break; } } cout<<r-l+1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...