89292024-02-05 17:46:48NagyLeoSzínes szobák (50 pont)pypy3Futási hiba 16/50141ms100044 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

    # for j in range(N):
    #    if kijute(j) != 0:
    #        left_people += 1

    # jobbra:
    lo = 0
    hi = N - 1
    if kijute(lo) == 1:
        print(N)
        return
    if kijute(hi) != 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 kijute(hi) == -1:
        print(N)
        return
    if kijute(lo) != -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()
RészfeladatÖsszpontTesztVerdiktIdőMemória
base16/50
1Elfogadva0/061ms87916 KiB
2Futási hiba0/075ms98416 KiB
3Elfogadva1/182ms94912 KiB
4Elfogadva1/197ms95156 KiB
5Elfogadva1/187ms94920 KiB
6Elfogadva1/187ms94952 KiB
7Elfogadva1/187ms94912 KiB
8Elfogadva1/187ms94924 KiB
9Elfogadva1/198ms94940 KiB
10Elfogadva1/1100ms96904 KiB
11Elfogadva1/179ms95436 KiB
12Elfogadva1/198ms97096 KiB
13Elfogadva1/1119ms97788 KiB
14Elfogadva1/1111ms97508 KiB
15Elfogadva1/1107ms98296 KiB
16Elfogadva1/1108ms98644 KiB
17Elfogadva1/1136ms98796 KiB
18Elfogadva1/1123ms98816 KiB
19Futási hiba0/167ms95284 KiB
20Futási hiba0/168ms95360 KiB
21Futási hiba0/168ms95380 KiB
22Futási hiba0/178ms94620 KiB
23Futási hiba0/170ms94972 KiB
24Futási hiba0/168ms94400 KiB
25Futási hiba0/168ms94616 KiB
26Futási hiba0/168ms94100 KiB
27Futási hiba0/368ms94816 KiB
28Futási hiba0/378ms94068 KiB
29Futási hiba0/368ms94548 KiB
30Futási hiba0/368ms93948 KiB
31Futási hiba0/376ms93816 KiB
32Futási hiba0/368ms93828 KiB
33Futási hiba0/4123ms100016 KiB
34Futási hiba0/4141ms100044 KiB