87762024-01-29 18:57:20NagyLeoKutyavetélkedőpypy3Wrong answer 85/100501ms198960 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

    # print(can_do)

    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):
        # print(i)
        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
1Accepted41ms76648 KiB
2Wrong answer50ms76908 KiB
subtask20/15
3Accepted43ms77508 KiB
4Accepted41ms78064 KiB
5Accepted39ms77928 KiB
6Accepted39ms78136 KiB
7Wrong answer119ms143692 KiB
8Accepted135ms144136 KiB
9Accepted123ms143888 KiB
subtask319/19
10Accepted48ms78476 KiB
11Accepted43ms79008 KiB
12Accepted46ms79104 KiB
13Accepted43ms78744 KiB
14Accepted39ms79168 KiB
15Accepted39ms79008 KiB
16Accepted39ms79132 KiB
subtask434/34
17Accepted101ms93416 KiB
18Accepted109ms94260 KiB
19Accepted104ms94832 KiB
20Accepted111ms94788 KiB
21Accepted108ms94904 KiB
22Accepted105ms96760 KiB
subtask532/32
23Accepted202ms128860 KiB
24Accepted237ms135560 KiB
25Accepted233ms139472 KiB
26Accepted231ms143096 KiB
27Accepted238ms144836 KiB
28Accepted312ms165044 KiB
29Accepted423ms198704 KiB
30Accepted501ms198960 KiB
31Accepted282ms175728 KiB
32Accepted228ms148416 KiB
33Accepted324ms183596 KiB
34Accepted317ms183512 KiB