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;
const int N = (int) 2e5 + 7;
const int INF = (int) 1e9 + 7;
int n;
int k;
int r;
int base[N];
int min_quantity[N];
int f[N];
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
///freopen ("input.txt", "r", stdin);
cin >> n >> k >> r;
for (int i = 0; i < n; i++) {
cin >> base[i];
}
for (int i = 0; i < r; i++) {
int base_id;
cin >> base_id;
cin >> min_quantity[base_id];
}
int unsolved_restrictions = r;
int l = 0, sol = INF;
for (int r = 0; r < n; r++) {
f[base[r]]++;
unsolved_restrictions -= (min_quantity[base[r]] > 0 && f[base[r]] == min_quantity[base[r]]);
if (unsolved_restrictions == 0) {
while (min_quantity[base[l]] == 0 || f[base[l]] != min_quantity[base[l]]) {
f[base[l++]]--;
}
sol = min(sol, r - l + 1);
}
}
if (sol == INF) {
cout << "impossible\n";
return 0;
}
cout << sol << "\n";
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... |