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;
const int mxN = 2e5+10;
int N, K, R;
void solve() {
cin >> N >> K >> R;
vector<int> DNA(N), need(K, INT_MAX);
for (auto& dna : DNA)
cin >> dna;
for (int i = 0; i < R; i++) {
int B, Q;
cin >> B >> Q;
need[B] = Q;
}
int ans = INT_MAX;
int good = 0;
for (int l = 0, r = 0; l < N; l++) {
while(good < R && r < N) {
if (--need[DNA[r++]] == 0)
++good;
}
if (good == R) {
cerr << l << ' ' << r << endl;
ans = min(ans, r - l);
}
if (++need[DNA[l]] == 1) {
--good;
}
}
cout << (ans == INT_MAX ? "impossible" : to_string(ans));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |