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 ll = long long;
int const nmax = 200000;
int v[1 + nmax], mn[1 + nmax], fr[1 + nmax];
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int n, k, r;
std::cin >> n >> k >> r;
for(int i = 1;i <= n; i++)
std::cin >> v[i];
for(int i = 1;i <= r; i++) {
int x, y;
std::cin >> x >> y;
mn[x] = y;
}
int j = 1, cnt = 0;
while(j <= n && cnt != r) {
fr[v[j]]++;
if(fr[v[j]] == mn[v[j]])
cnt++;
j++;
}
if(cnt != r) {
std::cout << "impossible";
return 0;
}
int ans = j - 1;
for(int i = 2;i <= n; i++) {
fr[v[i - 1]]--;
if(fr[v[i - 1]] < mn[v[i - 1]])
cnt--;
while(j <= n && cnt != r) {
fr[v[j]]++;
if(fr[v[j]] == mn[v[j]])
cnt++;
j++;
}
if(cnt != r)
break;
ans = std::min(ans, j - i);
}
std::cout << ans;
return 0;
}
# | 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... |