#include <iostream>
#include <vector>
#include <map>
#include <climits>
#define int long long
using namespace std;
signed main() {
int n, k, r, res = LLONG_MAX, 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;
cout << ri << "\n";
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++;
if(c[a[ri]]) sum[c[a[ri]]-1]++;
}
if(!ok) break;
}
res = min(res, ri-i);
}
cout << res << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
1884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
194 ms |
8788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |