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 fi first
#define se second
#define sst string
#define pb push_back
#define maxco 100000+5
#define lld long double
#define cha ios_base::sync_with_stdio(false);
#define ffl cout.flush();
#define phi acos(-1)
#define mr make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pqin priority_queue<ll,vector<ll>,greater<>>
#define pqpair priority_queue<pair<ll,ll> ,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define pqpair2 priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pi,pair<ll,ll>>>,greater<pair<pi,pair<ll,ll>>>>
#define INF 1000000009
#define MAXN 1000006
#define pii pair<ll,ll>
#define mod 998244353
ll a[MAXN];
ll n,k,r;
map<ll,ll> nd;
int main(){
cin>>n>>k>>r;
map<ll,ll> cnt;
REP(i,1,n){
cin>>a[i];
cnt[a[i]]++;
}
REP(i,1,r){
ll b,c;
cin>>b>>c;
nd[b]=c;
}
REP(i,0,k){
if(nd[i]>cnt[i]){
cout<<"Impossible"<<endl;
return 0;
}
}
ll l=1;
ll r=n;
while(l<r){
if(cnt[a[r]]>nd[a[r]]){
cnt[a[r]]--;
r--;
}
else if(cnt[a[l]]>nd[a[l]]){
cnt[a[l]]--;
l++;
}
else{
break;
}
}
cout<<r-l+1<<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... |