87752024-01-29 18:54:32NagyLeoKutyavetélkedőpypy3Wrong answer 0/100448ms199472 KiB
def max_points(K, N, M, pairs):
    can_do = [set() for i in range(N + 1)]
    for a, b in pairs:
        can_do[a].add(b)
    if T[0] > K and T[1] > K:
        return 0

    current_points = [0] * (N + 2)
    if T[N - 1] <= K:
        current_points[N - 1] = 1
    if T[N - 2] <= K:
        current_points[N - 2] = 1
        if T[N - 1] in can_do[T[N - 2]]:
            current_points[N - 2] = 2
    for i in range(N - 3, -1, -1):
        if T[i] <= K:
            current_points[i] = 1
            if T[i + 1] in can_do[T[i]]:
                current_points[i] = max(current_points[i], 1 + current_points[i + 1])
            if T[i + 2] in can_do[T[i]]:
                current_points[i] = max(current_points[i], 1 + current_points[i + 2])
        if T[i + 1] > K and T[i + 2] > K:
            return 0
        if T[i + 1] > K and T[i + 2] not in can_do[T[i]]:
            return 0
        if T[i + 1] not in can_do[T[i]] and T[i + 2] > K:
            return 0
        if T[i + 2] not in can_do[T[i]] and T[i + 1] not in can_do[T[i]] and T[i + 1] > K:
            return 0
    # print(current_points)

    return max(current_points[0], current_points[1])


N, K = map(int, input().split())
T = list(map(int, input().split()))
M = int(input())
pairs = [tuple(map(int, input().split())) for _ in range(M)]

print(max_points(K, N, M, pairs))
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted43ms77260 KiB
2Accepted41ms77824 KiB
subtask20/15
3Accepted39ms77828 KiB
4Accepted48ms78356 KiB
5Accepted43ms78596 KiB
6Accepted39ms78564 KiB
7Accepted119ms149996 KiB
8Wrong answer103ms150408 KiB
9Wrong answer98ms150492 KiB
subtask30/19
10Accepted41ms78616 KiB
11Accepted48ms79348 KiB
12Accepted43ms78972 KiB
13Accepted41ms79376 KiB
14Accepted48ms79784 KiB
15Wrong answer45ms80128 KiB
16Wrong answer48ms80036 KiB
subtask40/34
17Wrong answer89ms92736 KiB
18Wrong answer90ms93596 KiB
19Wrong answer93ms94164 KiB
20Wrong answer104ms95728 KiB
21Wrong answer96ms94116 KiB
22Wrong answer97ms93972 KiB
subtask50/32
23Wrong answer175ms121324 KiB
24Wrong answer215ms136108 KiB
25Wrong answer240ms140976 KiB
26Wrong answer222ms143564 KiB
27Wrong answer224ms145548 KiB
28Wrong answer326ms165460 KiB
29Wrong answer407ms199472 KiB
30Accepted448ms199236 KiB
31Wrong answer268ms176512 KiB
32Wrong answer207ms149976 KiB
33Wrong answer331ms182620 KiB
34Accepted344ms183544 KiB