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 ar array
#define int long long
#define ld long double
#define crash assert(69 == 420)
const int N = 2005;
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int X = 100;
map<int,int> mp;
int cnt;
void add(int x){
if(!mp.count(x))return;
mp[x]--;
if(mp[x] == 0)cnt--;
}
void rem(int x){
if(!mp.count(x))return;
if(mp[x] == 0)cnt++;
mp[x]++;
}
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
int n, k, r;
cin>>n>>k>>r;
int A[n];
for(int i = 0;i < n;i++)cin>>A[i];
//map<int, int> mp;
cnt = r;
while(r--){
int x, y;
cin>>x>>y;
mp[x] = y;
}
int mr = -1;
int ans = INF;
for(int i =0;i < n;i++){
while(mr + 1 < n && cnt)add(A[++mr]);
if(!cnt)ans = min(ans, mr - i + 1);
rem(A[i]);
}
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... |