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 fi first
#define se second
typedef long long ll;
typedef pair<int,int> ii;
const int INF = 1e9;
int n, k, r;
vector<int> a, need, cnt;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k >> r;
a = vector<int>(n+2);
need = cnt = vector<int>(k,0);
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= r; i++) {
int b, q; cin >> b >> q;
need[b] = q;
}
int ans = INF, get = 0;
for (int i = 1, j = 1; j <= n; i++) {
while (j <= n && get < r) {
cnt[a[j]]++;
get += (need[a[j]] && cnt[a[j]] == need[a[j]]);
j++;
}
// cout << i << " -> " << j << '\n';
if (get == r) ans = min(ans,j-i);
get -= (need[a[i]] && cnt[a[i]] == need[a[i]]);
cnt[a[i]]--;
}
if (ans == INF) 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... |