/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
int N, K, R;
int D[N_MAX + 2];
int Q[N_MAX + 2];
int cnt[N_MAX + 2];
int ok;
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 i = 1; i <= R; i++) {
int B;
cin >> B;
cin >> Q[B];
}
ok = K - R;
int r = 0;
while (r <= N && ok < K) {
r++;
if (cnt[D[r]] + 1 == Q[D[r]]) {
ok++;
}
cnt[D[r]]++;
}
if (r == N + 1) {
cout << "impossible\n";
return 0;
}
int answer = INT_MAX;
int l = 1;
while (r <= N) {
while (l < r && cnt[D[l]] - 1 >= Q[D[l]]) {
cnt[D[l]]--;
l++;
}
answer = min(answer, r - l + 1);
cnt[D[++r]]++;
}
cout << answer << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1108 KB |
Output is correct |
2 |
Correct |
10 ms |
1108 KB |
Output is correct |
3 |
Correct |
12 ms |
1040 KB |
Output is correct |
4 |
Correct |
13 ms |
1108 KB |
Output is correct |
5 |
Correct |
19 ms |
1364 KB |
Output is correct |
6 |
Correct |
11 ms |
1488 KB |
Output is correct |
7 |
Correct |
12 ms |
1620 KB |
Output is correct |
8 |
Correct |
19 ms |
3124 KB |
Output is correct |
9 |
Correct |
15 ms |
2000 KB |
Output is correct |
10 |
Correct |
12 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
1992 KB |
Output is correct |
2 |
Correct |
23 ms |
3128 KB |
Output is correct |
3 |
Correct |
19 ms |
2768 KB |
Output is correct |
4 |
Correct |
15 ms |
1488 KB |
Output is correct |
5 |
Correct |
29 ms |
4028 KB |
Output is correct |
6 |
Correct |
31 ms |
4468 KB |
Output is correct |
7 |
Correct |
16 ms |
2132 KB |
Output is correct |
8 |
Correct |
26 ms |
2328 KB |
Output is correct |
9 |
Correct |
11 ms |
1420 KB |
Output is correct |
10 |
Correct |
11 ms |
1480 KB |
Output is correct |
11 |
Correct |
12 ms |
1532 KB |
Output is correct |
12 |
Correct |
11 ms |
1524 KB |
Output is correct |
13 |
Correct |
16 ms |
2508 KB |
Output is correct |
14 |
Correct |
11 ms |
1484 KB |
Output is correct |
15 |
Correct |
10 ms |
1656 KB |
Output is correct |
16 |
Correct |
18 ms |
3148 KB |
Output is correct |
17 |
Correct |
14 ms |
2056 KB |
Output is correct |
18 |
Correct |
11 ms |
1536 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |