#include <iostream>
#include <vector>
#include <map>
#include <climits>
using namespace std;
int main() {
int n, k, r, res, le, ri, mid, ans;
bool ok;
map<int,int> c;
cin >> n >> k >> r;
vector<int> a(n);
vector<pair<int,int>> b(r);
vector<vector<int>> prefix(n, vector<int>(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;
}
if(c[a[0]]) prefix[0][c[a[0]]-1]++;
for(int i = 1; i < n; i++) {
for(int j = 0; j < r; j++) prefix[i][j] = prefix[i-1][j];
if(c[a[i]]) prefix[i][c[a[i]]-1]++;
}
for(int z = 0; z < r; z++) {
if(prefix[n-1][z] < b[z].second) {
cout << "impossible\n";
return 0;
}
}
for(int i = 0; i < n; i++) {
le = i, ri = n, ans = INT_MAX;
while(le<ri) {
mid = (le+ri)/2;
ok = true;
for(int j = 0; j < r; j++) {
if(prefix[mid][j]-(i == 0 ? 0 : prefix[i-1][j]) < b[j].second) {
ok = false;
break;
}
}
if(ok) {
ri = mid-1;
ans = mid;
}
else le = mid+1;
}
res = min(res, ans-i+1);
}
cout << res << "\n";
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:51:20: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | cout << res << "\n";
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
47 ms |
15684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
460 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |