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 <iostream>
#include <vector>
#include <map>
#include <climits>
#define int long long
using namespace std;
signed main() {
int n, k, r, res, ri = -1;
bool ok;
map<int,int> c;
cin >> n >> k >> r;
vector<int> a(n), sum(r);
vector<pair<int,int>> b(r);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < r; i++) {
cin >> b[i].first >> b[i].second;
c[b[i].first] = i+1;
}
//find start
while(true) {
if(ri == n-1) {
cout << "impossible\n";
return 0;
}
ri++;
if(c[a[ri]]) {
sum[c[a[ri]]-1]++;
ok = true;
for(int i = 0; i < r; i++) {
if(sum[i] < b[i].second) {
ok = false;
break;
}
}
if(ok) break;
}
}
//start
res = ri+1;
for(int i = 0; i < n; i++) {
if(c[a[i]]) sum[c[a[i]]-1]--;
ok = true;
while(sum[c[a[i]]-1] < b[c[a[i]]-1].second) {
if(ri == n-1) {
ok = false;
break;
}
ri++;
sum[c[a[ri]]-1]++;
}
if(!ok) break;
res = min(res, ri-i+1);
}
cout << res << "\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... |