89302024-02-05 17:50:16NagyLeoSzínes szobák (50 pont)python3Time limit exceeded 16/50388ms36348 KiB
def main():
    N, K, M = map(int, input().split())
    rooms_raw = list(map(int, input().split()))
    rooms = []

    for i in rooms_raw:
        rooms.append([i, 1])

    left_people = 0
    for i in range(M):
        color, direct = map(int, input().split())

        for j in range(N):
            if rooms[j][0] == color:
                if j + direct > N - 1 or j + direct < 0:
                    left_people += rooms[j][1]
                    rooms[j][1] = 0
                else:
                    rooms[j + direct][1] += rooms[j][1]
                    rooms[j][1] = 0
    print(left_people)


def main2():
    N, K, M = map(int, input().split())
    rooms = [int(x) for x in input().split()]

    left_people = 0
    rules = []
    for i in range(M):
        rules.append([int(x) for x in input().split()])

    def kijute(i):
        # az i. emberrel mi tortenik?
        # balra, nem jut ki , jobbra  -1, 0, 1

        for j in range(M):
            if rooms[i] == rules[j][0]:
                i += rules[j][1]
                if i > N - 1:
                    return 1
                elif i < 0:
                    return -1

        return 0

    elso = kijute(0)
    utolso = kijute(N - 1)
    # jobbra:
    lo = 0
    hi = N - 1
    if elso == 1:
        print(N)
        return
    if utolso != 1:
        pass
    else:
        while hi - lo > 1:
            half = (hi + lo) // 2
            if kijute(half) == 1:
                hi = half
            else:
                lo = half
        left_people += N - hi
    # balra:
    lo = 0
    hi = N - 1
    if utolso == -1:
        print(N)
        return
    if elso != -1:
        pass
    else:
        while hi - lo > 1:
            half = (hi + lo) // 2
            if kijute(half) == -1:
                lo = half
            else:
                hi = half
        left_people += hi

    print(left_people)


main2()
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/018ms11760 KiB
2Time limit exceeded0/0358ms21360 KiB
3Accepted1/121ms12508 KiB
4Accepted1/121ms12688 KiB
5Accepted1/120ms12496 KiB
6Accepted1/120ms12712 KiB
7Accepted1/121ms13056 KiB
8Accepted1/121ms12784 KiB
9Accepted1/121ms12980 KiB
10Accepted1/126ms13196 KiB
11Accepted1/121ms12744 KiB
12Accepted1/128ms13336 KiB
13Accepted1/168ms15476 KiB
14Accepted1/129ms14220 KiB
15Accepted1/130ms14852 KiB
16Accepted1/167ms16088 KiB
17Accepted1/174ms16916 KiB
18Accepted1/175ms16748 KiB
19Time limit exceeded0/1310ms36348 KiB
20Time limit exceeded0/1356ms23232 KiB
21Time limit exceeded0/1368ms18112 KiB
22Time limit exceeded0/1356ms19508 KiB
23Time limit exceeded0/1365ms22508 KiB
24Time limit exceeded0/1381ms23684 KiB
25Time limit exceeded0/1368ms23724 KiB
26Time limit exceeded0/1388ms23728 KiB
27Time limit exceeded0/3372ms21624 KiB
28Time limit exceeded0/3340ms21692 KiB
29Time limit exceeded0/3365ms21560 KiB
30Time limit exceeded0/3377ms21700 KiB
31Time limit exceeded0/3351ms21708 KiB
32Time limit exceeded0/3368ms21668 KiB
33Time limit exceeded0/4354ms29248 KiB
34Time limit exceeded0/4356ms20540 KiB