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>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define lso(x) x&(-x)
int n, k, r;
vi dna;
vi minr;
map<int,int> cmp;
vi ocs;
bool yes() {
rep(i,0,r) {
if (ocs[i] < minr[i]) return false;
}
return true;
}
int main()
{
cin>>n>>k>>r;
dna.resize(n);
minr.resize(r);
rep(i,0,n) cin>>dna[i];
int b, q, cm=0;
rep(i,0,r) {
cin>>b>>q;
cmp[b] = cm;cm++;
minr[cmp[b]] = q;
}
ocs.resize(r, 0);
int s = 0, e = 0, minl = 10000000;
if (cmp.find(dna[0]) != cmp.end()) ocs[cmp[dna[0]]]++;
while (e < n) {
if (yes()) { minl = min(minl, e - s);
if (cmp.find(dna[s]) != cmp.end()) ocs[cmp[dna[s]]]--;
s++;
}
else { e++;
if (cmp.find(dna[e]) != cmp.end()) ocs[dna[e]]++;
}
}
if (minl!=10000000) cout << minl+1 << endl;
else cout << "impossible" <<endl;
}
# | 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... |