87782024-01-29 19:00:30NagyLeoKutyavetélkedőpypy3Accepted 100/100493ms200136 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
1Accepted48ms76612 KiB
2Accepted48ms77180 KiB
subtask215/15
3Accepted48ms77396 KiB
4Accepted46ms77648 KiB
5Accepted48ms77824 KiB
6Accepted46ms77560 KiB
7Accepted123ms143760 KiB
8Accepted142ms143804 KiB
9Accepted126ms144004 KiB
subtask319/19
10Accepted39ms78116 KiB
11Accepted46ms78480 KiB
12Accepted43ms78600 KiB
13Accepted41ms79624 KiB
14Accepted46ms79516 KiB
15Accepted43ms79848 KiB
16Accepted48ms79860 KiB
subtask434/34
17Accepted97ms93396 KiB
18Accepted103ms94524 KiB
19Accepted103ms95876 KiB
20Accepted104ms95944 KiB
21Accepted105ms95772 KiB
22Accepted119ms97700 KiB
subtask532/32
23Accepted212ms130240 KiB
24Accepted238ms135968 KiB
25Accepted233ms140684 KiB
26Accepted256ms144608 KiB
27Accepted277ms146724 KiB
28Accepted342ms166452 KiB
29Accepted493ms199836 KiB
30Accepted456ms200136 KiB
31Accepted287ms176972 KiB
32Accepted230ms149400 KiB
33Accepted324ms184616 KiB
34Accepted361ms184592 KiB