89332024-02-05 18:05:29NagyLeoSzínes szobák (50 pont)python3Time limit exceeded 17/50402ms35916 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=[0]*M
    for i in range(M):
        rules[i]=[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
base17/50
1Accepted0/017ms11544 KiB
2Time limit exceeded0/0402ms21936 KiB
3Accepted1/120ms12492 KiB
4Accepted1/120ms12336 KiB
5Accepted1/120ms12776 KiB
6Accepted1/120ms13216 KiB
7Accepted1/120ms13036 KiB
8Accepted1/120ms12936 KiB
9Accepted1/121ms13240 KiB
10Accepted1/125ms13736 KiB
11Accepted1/121ms13156 KiB
12Accepted1/127ms13620 KiB
13Accepted1/161ms15836 KiB
14Accepted1/128ms14384 KiB
15Accepted1/128ms14496 KiB
16Accepted1/159ms16028 KiB
17Accepted1/165ms16612 KiB
18Accepted1/168ms16364 KiB
19Accepted1/1280ms35916 KiB
20Time limit exceeded0/1354ms23164 KiB
21Time limit exceeded0/1356ms17588 KiB
22Time limit exceeded0/1381ms19524 KiB
23Time limit exceeded0/1381ms22432 KiB
24Time limit exceeded0/1377ms23980 KiB
25Time limit exceeded0/1388ms23988 KiB
26Time limit exceeded0/1388ms23864 KiB
27Time limit exceeded0/3388ms20808 KiB
28Time limit exceeded0/3377ms21048 KiB
29Time limit exceeded0/3377ms21112 KiB
30Time limit exceeded0/3351ms21156 KiB
31Time limit exceeded0/3372ms21356 KiB
32Time limit exceeded0/3372ms21312 KiB
33Time limit exceeded0/4314ms28848 KiB
34Time limit exceeded0/4344ms20292 KiB