89322024-02-05 18:02:20NagyLeoSzínes szobák (50 pont)pypy3Runtime error 16/5094ms100068 KiB
from sys import stdin, stdout

input = stdin.readline


def print(x):
    stdout.write(str(x) + "\n")


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/061ms87932 KiB
2Runtime error0/076ms98172 KiB
3Accepted1/167ms94956 KiB
4Accepted1/161ms94912 KiB
5Accepted1/171ms94660 KiB
6Accepted1/164ms95064 KiB
7Accepted1/171ms94872 KiB
8Accepted1/171ms94724 KiB
9Accepted1/171ms95168 KiB
10Accepted1/179ms96144 KiB
11Accepted1/164ms94956 KiB
12Accepted1/170ms96376 KiB
13Accepted1/186ms97172 KiB
14Accepted1/174ms96372 KiB
15Accepted1/171ms96476 KiB
16Accepted1/175ms97116 KiB
17Accepted1/190ms96824 KiB
18Accepted1/190ms96816 KiB
19Runtime error0/176ms95404 KiB
20Runtime error0/179ms94860 KiB
21Runtime error0/170ms94592 KiB
22Runtime error0/179ms95096 KiB
23Runtime error0/168ms94604 KiB
24Runtime error0/175ms94380 KiB
25Runtime error0/175ms94592 KiB
26Runtime error0/178ms94308 KiB
27Runtime error0/370ms94316 KiB
28Runtime error0/376ms94104 KiB
29Runtime error0/374ms94408 KiB
30Runtime error0/368ms94368 KiB
31Runtime error0/376ms94504 KiB
32Runtime error0/374ms94220 KiB
33Runtime error0/494ms100060 KiB
34Runtime error0/494ms100068 KiB