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(0); cin.tie(0);
int n, k, r; cin >> n >> k >> r;
vector<int> v(n);
for(auto &x : v)cin >> x;
vector<int> ha(k,0), wa(k,0);
for(int i = 0; i < r; ++i){
int a, b; cin >> a >> b;
wa[a] = b;
}
int l = -1, ri = -1, go = 0, best = 1<<30;
while(++ri < n){
ha[v[ri]]++;
if(ha[v[ri]] == wa[v[ri]])go++;
if(go == r){
while(go == r){
++l;
ha[v[l]]--;
if(ha[v[l]] == wa[v[l]]-1)go--;
}
best = min(best,ri-l+1);
}
}
cout << (best == (1<<30) ? "impossible" : to_string(best)) << "\n";
}
# | 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... |