89282024-02-05 17:46:21NagyLeoSzínes szobák (50 pont)python3Time limit exceeded 16/50388ms37156 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()
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/018ms11708 KiB
2Time limit exceeded0/0354ms21960 KiB
3Accepted1/123ms13120 KiB
4Accepted1/121ms13044 KiB
5Accepted1/121ms13048 KiB
6Accepted1/121ms13396 KiB
7Accepted1/123ms13420 KiB
8Accepted1/121ms14048 KiB
9Accepted1/121ms14040 KiB
10Accepted1/127ms14480 KiB
11Accepted1/123ms13860 KiB
12Accepted1/129ms14500 KiB
13Accepted1/168ms16796 KiB
14Accepted1/128ms15352 KiB
15Accepted1/130ms15440 KiB
16Accepted1/168ms16896 KiB
17Accepted1/175ms17588 KiB
18Accepted1/176ms17444 KiB
19Time limit exceeded0/1312ms37156 KiB
20Time limit exceeded0/1372ms24392 KiB
21Time limit exceeded0/1379ms19324 KiB
22Time limit exceeded0/1340ms21012 KiB
23Time limit exceeded0/1368ms24060 KiB
24Time limit exceeded0/1368ms25876 KiB
25Time limit exceeded0/1365ms26480 KiB
26Time limit exceeded0/1377ms26872 KiB
27Time limit exceeded0/3384ms24832 KiB
28Time limit exceeded0/3388ms25392 KiB
29Time limit exceeded0/3368ms25812 KiB
30Time limit exceeded0/3368ms26568 KiB
31Time limit exceeded0/3372ms26844 KiB
32Time limit exceeded0/3368ms27336 KiB
33Time limit exceeded0/4358ms35084 KiB
34Time limit exceeded0/4356ms26896 KiB