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 int long long
#define sp << " " <<
#define nl << "\n"
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, k, r; cin >> n >> k >> r;
int a[n], b[k];
fill(b, b+k, -n);
for(int i=0; i<n; ++i) cin >> a[i];
for(int i=0, j; i<r; ++i) cin >> j >> b[j];
int i = 0, curr = n-r, ans = 1e18;
for(int j=0; j<n; ++j){
curr += --b[a[j]]==0;
while(i<j and b[a[i]] < 0) ++b[a[i++]];
if(curr==n) ans = min(ans, j-i+1);
}
if(ans==(int)1e18) 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... |