/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
const int R_MAX = 10;
int N, K, R;
int D[N_MAX + 2];
int B[R_MAX + 2], Q[R_MAX + 2];
int pref[R_MAX + 2][N_MAX + 2];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> K >> R;
for (int i = 1; i <= N; i++) {
cin >> D[i];
}
for (int r = 1; r <= R; r++) {
cin >> B[r] >> Q[r];
for (int i = 1; i <= N; i++) {
pref[r][i] = pref[r][i - 1] + (D[i] == B[r]);
}
}
int answer = INT_MAX;
for (int i = 1; i <= N; i++) {
int lo = 0, hi = i;
while (lo < hi) {
int mid = (lo + hi + 1) / 2;
bool ok = true;
for (int r = 1; r <= K; r++) {
if (pref[r][i] - pref[r][mid - 1] < Q[r]) {
ok = false;
break;
}
}
if (ok == true) {
lo = mid;
} else {
hi = mid - 1;
}
}
if (lo > 0) {
answer = min(answer, i - lo + 1);
}
}
if (answer != INT_MAX) {
cout << answer << "\n";
} else {
cout << "impossible\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Runtime error |
3 ms |
852 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
8544 KB |
Output is correct |
2 |
Correct |
23 ms |
2244 KB |
Output is correct |
3 |
Correct |
69 ms |
9356 KB |
Output is correct |
4 |
Correct |
42 ms |
9328 KB |
Output is correct |
5 |
Runtime error |
35 ms |
18956 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
20860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |