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;
#define rep(n) for (int i = 0; i < n; ++i)
#define rep2(n) for (int j = 0; j < n; ++j)
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k, r;
cin >> n >> k >> r;
int d[n], cnt[k] = {}, mst[k] = {}, b, q, cur = 0, start = 0, ans = INT_MAX;
rep (n) cin >> d[i];
rep (r) {
cin >> b >> q;
mst[b] = q;
}
rep (n) {
cnt[d[i]]++;
if (cnt[d[i]]==mst[d[i]]) cur++;
while (cur==r) {
ans = min(ans, i-start+1);
if (cnt[d[start]]==mst[d[start]]) cur--;
cnt[d[start++]]--;
}
}
if (ans!=INT_MAX) cout << ans << "\n";
else cout << "impossible\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... |