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>
int main() {
std::ios::sync_with_stdio(0); std::cin.tie(0);
int n, k, m; std::cin >> n >> k >> m;
std::vector <int> a(n);
for (int& x : a) std::cin >> x;
std::vector <int> req(n, 0), has(n, 0);
int cntgood = n;
for (int i = 0; i < m; i++) {
int t, h; std::cin >> t >> h;
req[t] = h;
cntgood--;
}
int ans = 1 << 30;
for (int l = 0, r = 0; r < n; r++) {
has[a[r]]++;
if (has[a[r]] == req[a[r]]) cntgood++;
while (cntgood == n && has[a[l]] > req[a[l]]) has[a[l++]]--;
if (cntgood == n) ans = std::min(ans, r - l + 1);
}
if (ans == 1 << 30) std::cout << "impossible\n";
else std::cout << ans << "\n";
std::cout.flush();
std::cin >> n;
}
# | 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... |