#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k, r;
cin >> n >> k >> r;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> c(k, -1);
for (int i = 0; i < r; ++i) {
int b, q;
cin >> b >> q;
c[b] = q;
}
int ok = k - r;
vector<int> cnt(k);
auto add = [&](int ind, int v) {
ok -= cnt[a[ind]] >= c[a[ind]];
cnt[a[ind]] += v;
ok += cnt[a[ind]] >= c[a[ind]];
};
int ans = n + 1;
for (int pl = 0, pr = 0; pl < n; ++pl) {//[l, r)
pr = max(pr, pl);
while (pr < n && ok < k) {
add(pr, 1);
pr++;
}
if (ok == k) {
ans = min(ans, pr - pl);
}
add(pl, -1);
}
if (ans == n + 1) {
cout << "impossible" << '\n';
} else {
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1624 KB |
Output is correct |
2 |
Correct |
11 ms |
1628 KB |
Output is correct |
3 |
Correct |
11 ms |
1492 KB |
Output is correct |
4 |
Correct |
9 ms |
1624 KB |
Output is correct |
5 |
Correct |
14 ms |
2916 KB |
Output is correct |
6 |
Correct |
9 ms |
1628 KB |
Output is correct |
7 |
Correct |
10 ms |
1732 KB |
Output is correct |
8 |
Correct |
16 ms |
3932 KB |
Output is correct |
9 |
Correct |
12 ms |
2136 KB |
Output is correct |
10 |
Correct |
10 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
544 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
0 ms |
456 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3420 KB |
Output is correct |
2 |
Correct |
19 ms |
3252 KB |
Output is correct |
3 |
Correct |
16 ms |
2904 KB |
Output is correct |
4 |
Correct |
10 ms |
1624 KB |
Output is correct |
5 |
Correct |
27 ms |
4172 KB |
Output is correct |
6 |
Correct |
26 ms |
4688 KB |
Output is correct |
7 |
Correct |
13 ms |
2140 KB |
Output is correct |
8 |
Correct |
15 ms |
2396 KB |
Output is correct |
9 |
Correct |
9 ms |
1628 KB |
Output is correct |
10 |
Correct |
10 ms |
1628 KB |
Output is correct |
11 |
Correct |
12 ms |
1628 KB |
Output is correct |
12 |
Correct |
10 ms |
1612 KB |
Output is correct |
13 |
Correct |
18 ms |
3016 KB |
Output is correct |
14 |
Correct |
9 ms |
1628 KB |
Output is correct |
15 |
Correct |
10 ms |
1628 KB |
Output is correct |
16 |
Correct |
16 ms |
3928 KB |
Output is correct |
17 |
Correct |
12 ms |
2140 KB |
Output is correct |
18 |
Correct |
9 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
456 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |