def validacao(v, w, n,k,r):
t = [0] * k
for x in v:
t[x] += 1
for i in range(k):
if w[i] > t[i]:
return False
#if w[i] > n:
# return False
return True
n,k,r = map(int, input().split())
v = list(map(int, input().split()))
#if r < 1 or k < 1 or n<1:
# print("impossible")
# exit(0)
#
#if k > n:
# print("impossible")
# exit(0)
#
#if r > k:
# exit(0)
# print("impossible")
failed = 0
have = [0] * k
wanted = [0] * k
for i in range(r):
sym, co = map(int, input().split())
wanted[sym] = co
failed += 1
#print(f"falha: {failed}")
if not validacao(v, wanted, n,k,r):
print("impossible")
exit(0)
j = 0
d = 0
i = 0
res = 999999999999999
while True:
if failed > 0:
if j == n:
break
have[v[j]] += 1
if have[v[j]] == wanted[v[j]]:
failed -= 1
j += 1
else:
dif = j - i
if dif < res:
res = dif
if have[v[i]] == wanted[v[i]]:
failed += 1
have[v[i]] -= 1
i += 1
#if i > n:
# break
if res == 999999999999999:
print("impossible")
exit(0)
print(res)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2936 KB |
Output is correct |
2 |
Correct |
15 ms |
2868 KB |
Output is correct |
3 |
Correct |
14 ms |
2932 KB |
Output is correct |
4 |
Correct |
13 ms |
2860 KB |
Output is correct |
5 |
Correct |
15 ms |
2900 KB |
Output is correct |
6 |
Correct |
14 ms |
2936 KB |
Output is correct |
7 |
Correct |
13 ms |
2840 KB |
Output is correct |
8 |
Correct |
14 ms |
2844 KB |
Output is correct |
9 |
Correct |
13 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
2932 KB |
Output is correct |
2 |
Correct |
18 ms |
2936 KB |
Output is correct |
3 |
Correct |
18 ms |
3316 KB |
Output is correct |
4 |
Correct |
19 ms |
3436 KB |
Output is correct |
5 |
Correct |
17 ms |
3284 KB |
Output is correct |
6 |
Correct |
19 ms |
2932 KB |
Output is correct |
7 |
Correct |
13 ms |
2916 KB |
Output is correct |
8 |
Correct |
13 ms |
2900 KB |
Output is correct |
9 |
Correct |
13 ms |
2840 KB |
Output is correct |
10 |
Correct |
13 ms |
2900 KB |
Output is correct |
11 |
Correct |
13 ms |
2948 KB |
Output is correct |
12 |
Correct |
13 ms |
2844 KB |
Output is correct |
13 |
Correct |
13 ms |
2896 KB |
Output is correct |
14 |
Correct |
13 ms |
2904 KB |
Output is correct |
15 |
Correct |
13 ms |
2840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
260 ms |
6460 KB |
Output is correct |
2 |
Correct |
289 ms |
6448 KB |
Output is correct |
3 |
Correct |
319 ms |
9792 KB |
Output is correct |
4 |
Correct |
289 ms |
7944 KB |
Output is correct |
5 |
Correct |
267 ms |
27340 KB |
Output is correct |
6 |
Correct |
172 ms |
6536 KB |
Output is correct |
7 |
Correct |
67 ms |
18720 KB |
Output is correct |
8 |
Correct |
297 ms |
26264 KB |
Output is correct |
9 |
Correct |
258 ms |
26412 KB |
Output is correct |
10 |
Correct |
237 ms |
6544 KB |
Output is correct |
11 |
Correct |
18 ms |
2900 KB |
Output is correct |
12 |
Correct |
19 ms |
2928 KB |
Output is correct |
13 |
Correct |
18 ms |
3388 KB |
Output is correct |
14 |
Correct |
19 ms |
3460 KB |
Output is correct |
15 |
Correct |
17 ms |
3328 KB |
Output is correct |
16 |
Correct |
20 ms |
2932 KB |
Output is correct |
17 |
Correct |
13 ms |
2900 KB |
Output is correct |
18 |
Correct |
13 ms |
2900 KB |
Output is correct |
19 |
Correct |
13 ms |
2904 KB |
Output is correct |
20 |
Correct |
13 ms |
2900 KB |
Output is correct |
21 |
Correct |
14 ms |
2900 KB |
Output is correct |
22 |
Correct |
13 ms |
2816 KB |
Output is correct |
23 |
Correct |
13 ms |
2900 KB |
Output is correct |
24 |
Correct |
14 ms |
2872 KB |
Output is correct |
25 |
Correct |
13 ms |
2876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
463 ms |
27568 KB |
Output is correct |
2 |
Correct |
441 ms |
27564 KB |
Output is correct |
3 |
Correct |
321 ms |
27476 KB |
Output is correct |
4 |
Correct |
305 ms |
6616 KB |
Output is correct |
5 |
Correct |
248 ms |
27632 KB |
Output is correct |
6 |
Correct |
484 ms |
28960 KB |
Output is correct |
7 |
Correct |
205 ms |
26740 KB |
Output is correct |
8 |
Correct |
255 ms |
27272 KB |
Output is correct |
9 |
Correct |
235 ms |
6492 KB |
Output is correct |
10 |
Correct |
300 ms |
6544 KB |
Output is correct |
11 |
Correct |
324 ms |
9792 KB |
Output is correct |
12 |
Correct |
274 ms |
7768 KB |
Output is correct |
13 |
Correct |
274 ms |
27448 KB |
Output is correct |
14 |
Correct |
156 ms |
6552 KB |
Output is correct |
15 |
Correct |
67 ms |
18800 KB |
Output is correct |
16 |
Correct |
297 ms |
26268 KB |
Output is correct |
17 |
Correct |
249 ms |
26524 KB |
Output is correct |
18 |
Correct |
258 ms |
6416 KB |
Output is correct |
19 |
Correct |
19 ms |
2900 KB |
Output is correct |
20 |
Correct |
17 ms |
3028 KB |
Output is correct |
21 |
Correct |
17 ms |
3336 KB |
Output is correct |
22 |
Correct |
19 ms |
3452 KB |
Output is correct |
23 |
Correct |
19 ms |
3324 KB |
Output is correct |
24 |
Correct |
19 ms |
2996 KB |
Output is correct |
25 |
Correct |
13 ms |
2824 KB |
Output is correct |
26 |
Correct |
13 ms |
2932 KB |
Output is correct |
27 |
Correct |
15 ms |
2928 KB |
Output is correct |
28 |
Correct |
13 ms |
2944 KB |
Output is correct |
29 |
Correct |
13 ms |
2928 KB |
Output is correct |
30 |
Correct |
14 ms |
2936 KB |
Output is correct |
31 |
Correct |
13 ms |
2900 KB |
Output is correct |
32 |
Correct |
13 ms |
2900 KB |
Output is correct |
33 |
Correct |
13 ms |
2932 KB |
Output is correct |