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;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int mn = 2e5 + 5;
int a[mn], delta[mn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, k, r; cin >> n >> k >> r;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i < r; i++) {
int b, q; cin >> b >> q;
delta[b] = -q;
}
int start = 0;
for (int i = 0; i < k; i++) {
while (start + 1 <= n && delta[i] < 0) delta[a[++start]]++;
if (delta[i] < 0) return cout << "impossible", 0;
}
int ans = start;
for (int L = 1, R = start; R <= n; R++) {
if (R != start) delta[a[R]]++;
while (L < R && delta[a[L]] > 0) delta[a[L++]]--;
ans = min(ans, R - L + 1);
}
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... |