87782024-01-29 19:00:30NagyLeoKutyavetélkedőpypy3Elfogadva 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))
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva48ms76612 KiB
2Elfogadva48ms77180 KiB
subtask215/15
3Elfogadva48ms77396 KiB
4Elfogadva46ms77648 KiB
5Elfogadva48ms77824 KiB
6Elfogadva46ms77560 KiB
7Elfogadva123ms143760 KiB
8Elfogadva142ms143804 KiB
9Elfogadva126ms144004 KiB
subtask319/19
10Elfogadva39ms78116 KiB
11Elfogadva46ms78480 KiB
12Elfogadva43ms78600 KiB
13Elfogadva41ms79624 KiB
14Elfogadva46ms79516 KiB
15Elfogadva43ms79848 KiB
16Elfogadva48ms79860 KiB
subtask434/34
17Elfogadva97ms93396 KiB
18Elfogadva103ms94524 KiB
19Elfogadva103ms95876 KiB
20Elfogadva104ms95944 KiB
21Elfogadva105ms95772 KiB
22Elfogadva119ms97700 KiB
subtask532/32
23Elfogadva212ms130240 KiB
24Elfogadva238ms135968 KiB
25Elfogadva233ms140684 KiB
26Elfogadva256ms144608 KiB
27Elfogadva277ms146724 KiB
28Elfogadva342ms166452 KiB
29Elfogadva493ms199836 KiB
30Elfogadva456ms200136 KiB
31Elfogadva287ms176972 KiB
32Elfogadva230ms149400 KiB
33Elfogadva324ms184616 KiB
34Elfogadva361ms184592 KiB