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>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 2e5+1, INF = 1e9;
int n, k, r;
int a[N];
int q[N];
int cur[N];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> k >> r;
for (int i = 1; i <= n; cin >> a[i++]);
for (int i = 1, b; i <= r; cin >> b >> q[b], i++);
int sat = (++cur[a[1]] == 1);
int l = 1, r = 1;
int sol = INF;
while (r <= n) {
if (sat == k && l < r) {
sol = min(sol, r-l+1);
cur[a[l]]--;
if (cur[a[l]] == q[a[l]]-1) sat--;
l++;
} else {
r++;
cur[a[r]]++;
if (cur[a[r]] == q[a[r]]) sat++;
}
}
cout << (sol == INF ? "impossible" : to_string(sol));
}
# | 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... |