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;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5+10;
int a[N], b[N], cnt[N], cc=0, n, k, r;
void add(int x) {
++cnt[x];
if (cnt[x] == b[x]) ++cc;
}
void rem(int x) {
--cnt[x];
if (cnt[x] == b[x]-1) --cc;
}
void solve() {
cin>>n>>k>>r;
for (int i=1; i<=n; ++i) cin>>a[i], ++a[i];
for (int i=1; i<=r; ++i) {
int k, x; cin>>k>>x; ++k;
b[k]=x;
}
for (int i=1; i<=k; ++i) {
if (b[i] == 0) ++cc;
}
int ans=n+1, r=1;
while (r <= n && cc < k) add(a[r++]);
assert(cc <= k);
if (cc < k) {
cout<<"impossible\n";
return;
}
ans=r-1;
for (int l=1; l<=n; ++l) {
if (cc == k) ans=min(ans, r-l);
rem(a[l]);
while (r <= n && cc < k) add(a[r++]);
} cout<<ans<<"\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
while (t--) solve();
}
# | 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... |