87772024-01-29 18:58:35NagyLeoKutyavetélkedőpypy3Wrong answer 100/100435ms199444 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
1Accepted48ms76892 KiB
2Wrong answer46ms76864 KiB
subtask215/15
3Accepted43ms77476 KiB
4Accepted39ms77344 KiB
5Accepted48ms77912 KiB
6Accepted48ms77724 KiB
7Accepted136ms143636 KiB
8Accepted136ms143544 KiB
9Accepted123ms144144 KiB
subtask319/19
10Accepted41ms78996 KiB
11Accepted41ms79092 KiB
12Accepted48ms79124 KiB
13Accepted46ms79380 KiB
14Accepted43ms79420 KiB
15Accepted39ms79508 KiB
16Accepted48ms79784 KiB
subtask434/34
17Accepted103ms93480 KiB
18Accepted105ms94584 KiB
19Accepted101ms96244 KiB
20Accepted112ms95980 KiB
21Accepted108ms95724 KiB
22Accepted116ms97524 KiB
subtask532/32
23Accepted208ms130032 KiB
24Accepted234ms136324 KiB
25Accepted231ms139948 KiB
26Accepted234ms143576 KiB
27Accepted259ms145204 KiB
28Accepted344ms165700 KiB
29Accepted435ms199168 KiB
30Accepted428ms199444 KiB
31Accepted282ms176676 KiB
32Accepted226ms148696 KiB
33Accepted324ms183828 KiB
34Accepted363ms183836 KiB