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 pair<int, int> ii;
typedef long long ll;
const int INF = 1e9;
const int MAXN = 2e5 + 5;
const ll LINF = 1e18;
const double pi = acos(-1);
const double EPS = 1e-9;
template <class T> using MinPQ = priority_queue<T, vector<T>, greater<T>>;
template <class T> using MaxPQ = priority_queue<T>;
int n, k, r;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> k >> r;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> q(k);
int numOfMatched = k - r;
for (int i = 0; i < r; i++) {
int b;
cin >> b;
cin >> q[b];
}
int j = 0;
vector<int> matched(k, 0);
int ans = 1e9;
int curLen = 0;
for (int i = 0; i < n; i++) {
matched[a[i]]++; ++curLen;
if (matched[a[i]] == q[a[i]]) ++numOfMatched;
if (numOfMatched == k) ans = min(ans, curLen);
while (j <= i && numOfMatched == k) {
matched[a[j]]--;
if (matched[a[j]] < q[a[j]]) numOfMatched--;
j++;
curLen--;
if (numOfMatched == k) ans = min(ans, curLen);
}
}
if (ans > n) cout << "impossible\n";
else cout << ans << "\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... |