#include <bits/stdc++.h>
using ll = long long;
int const nmax = 200000;
int v[1 + nmax], mn[1 + nmax], fr[1 + nmax];
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int n, k, r;
std::cin >> n >> k >> r;
for(int i = 1;i <= n; i++)
std::cin >> v[i];
for(int i = 1;i <= r; i++) {
int x, y;
std::cin >> x >> y;
mn[x] = y;
}
int j = 1, cnt = 0;
while(j <= n && cnt != r) {
fr[v[j]]++;
if(fr[v[j]] == mn[v[j]])
cnt++;
j++;
}
if(cnt != r) {
std::cout << "impossible";
return 0;
}
int ans = j - 1;
for(int i = 2;i <= n; i++) {
fr[v[i - 1]]--;
if(fr[v[i - 1]] < mn[v[i - 1]])
cnt--;
while(j <= n && cnt != r) {
fr[v[j]]++;
if(fr[v[j]] == mn[v[j]])
cnt++;
j++;
}
if(cnt != r)
break;
ans = std::min(ans, j - i);
}
std::cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 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 |
360 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1492 KB |
Output is correct |
2 |
Correct |
11 ms |
1488 KB |
Output is correct |
3 |
Correct |
12 ms |
1520 KB |
Output is correct |
4 |
Correct |
11 ms |
1412 KB |
Output is correct |
5 |
Correct |
18 ms |
2480 KB |
Output is correct |
6 |
Correct |
10 ms |
1424 KB |
Output is correct |
7 |
Correct |
11 ms |
1620 KB |
Output is correct |
8 |
Correct |
20 ms |
3132 KB |
Output is correct |
9 |
Correct |
17 ms |
2152 KB |
Output is correct |
10 |
Correct |
12 ms |
1440 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 |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3412 KB |
Output is correct |
2 |
Correct |
24 ms |
3056 KB |
Output is correct |
3 |
Correct |
21 ms |
2756 KB |
Output is correct |
4 |
Correct |
11 ms |
1492 KB |
Output is correct |
5 |
Correct |
29 ms |
4032 KB |
Output is correct |
6 |
Correct |
45 ms |
4556 KB |
Output is correct |
7 |
Correct |
17 ms |
2144 KB |
Output is correct |
8 |
Correct |
19 ms |
2388 KB |
Output is correct |
9 |
Correct |
12 ms |
1492 KB |
Output is correct |
10 |
Correct |
12 ms |
1448 KB |
Output is correct |
11 |
Correct |
13 ms |
1496 KB |
Output is correct |
12 |
Correct |
13 ms |
1492 KB |
Output is correct |
13 |
Correct |
17 ms |
2472 KB |
Output is correct |
14 |
Correct |
10 ms |
1492 KB |
Output is correct |
15 |
Correct |
11 ms |
1612 KB |
Output is correct |
16 |
Correct |
19 ms |
3152 KB |
Output is correct |
17 |
Correct |
16 ms |
2148 KB |
Output is correct |
18 |
Correct |
12 ms |
1508 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 |
340 KB |
Output is correct |
22 |
Correct |
1 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 |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |