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;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k, r;
cin >> n >> k >> r;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
vector<int> need(k);
vector<int> cnt(k);
for(int i = 0; i < r; i++){
int b, q;
cin >> b >> q;
need[b] = q;
}
int lp = 1;
int ans = -1;
int ok = r;
for(int i = 1; i <= n; i++){
cnt[a[i]]++;
if(cnt[a[i]] == need[a[i]]) ok--;
while(lp < i && ok == 0 && cnt[a[lp]] > need[a[lp]]){
cnt[a[lp]]--;
lp++;
}
if(ok != 0) continue;
int len = i - lp + 1;
if(ans == -1 || len < ans) ans = len;
}
if(ans == -1) 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... |