89312024-02-05 17:55:30NagyLeoSzínes szobák (50 pont)python3Time limit exceeded 17/50400ms37364 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
base17/50
1Accepted0/018ms11476 KiB
2Time limit exceeded0/0375ms21352 KiB
3Accepted1/121ms12596 KiB
4Accepted1/120ms12788 KiB
5Accepted1/120ms13016 KiB
6Accepted1/121ms13076 KiB
7Accepted1/120ms12784 KiB
8Accepted1/121ms13192 KiB
9Accepted1/120ms13284 KiB
10Accepted1/125ms13692 KiB
11Accepted1/123ms13592 KiB
12Accepted1/128ms13948 KiB
13Accepted1/161ms16356 KiB
14Accepted1/127ms14716 KiB
15Accepted1/128ms15184 KiB
16Accepted1/161ms16248 KiB
17Accepted1/165ms17180 KiB
18Accepted1/168ms17140 KiB
19Accepted1/1275ms36792 KiB
20Time limit exceeded0/1361ms23236 KiB
21Time limit exceeded0/1379ms37364 KiB
22Time limit exceeded0/1381ms19556 KiB
23Time limit exceeded0/1400ms22200 KiB
24Time limit exceeded0/1381ms23620 KiB
25Time limit exceeded0/1356ms23476 KiB
26Time limit exceeded0/1388ms23628 KiB
27Time limit exceeded0/3372ms20788 KiB
28Time limit exceeded0/3352ms20760 KiB
29Time limit exceeded0/3379ms21092 KiB
30Time limit exceeded0/3360ms20952 KiB
31Time limit exceeded0/3377ms21064 KiB
32Time limit exceeded0/3384ms21016 KiB
33Time limit exceeded0/4314ms28852 KiB
34Time limit exceeded0/4363ms20376 KiB