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 = 2e5 + 5;
int n, k, r, a[N], b[N], t[N], sum[N][10];
bool ok(int x, int y)
{
for(int i = 0; i < r; i++) {
int s = sum[y][i] - (x == 0 ? 0 : sum[x - 1][i]);
if(s < b[i]) {
return 0;
}
}
return 1;
}
int main()
{
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> k >> r;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < r; i++) {
int x, v;
cin >> x >> v;
b[i] = v;
t[i] = x;
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < r; j++) {
if(i > 0) sum[i][j] = sum[i - 1][j];
sum[i][j] += (a[i] == t[j]);
}
}
int ans = 1e9;
for(int i = 0; i < n; i++) {
int l = i, r = n - 1, z = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(ok(i, mid)) {
r = mid - 1, z = mid;
} else {
l = mid + 1;
}
}
if(z != -1) ans = min(ans, z - i + 1);
}
if(ans == 1e9) {
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... |