#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++;
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++) {
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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
26 ms |
3676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
133 ms |
16748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |