Submission #48143151


Source Code Expand

import sys
import heapq
from typing import List, Tuple

sys.setrecursionlimit(210000)


def eprint(*args, **kwargs):
    print(
        '[EPRINT]',
        *args, file=sys.stderr, **kwargs)


def main() -> None:
    _, _, L = map(int, input().split())
    mains = list((p, i) for i, p in enumerate(map(int, input().split())))
    subs = list((p, i) for i, p in enumerate(map(int, input().split())))
    bans = set(tuple(map(int, input().split())) for _ in range(L))

    mains.sort(reverse=True)
    subs.sort(reverse=True)
    queue: List[Tuple[int, int, int, int, int]] = []
    heapq.heappush(queue, (-mains[0][0] - subs[0][0], 0, 0, mains[0][1], subs[0][1]))

    while True:
        price, i, j, midx, sidx = heapq.heappop(queue)
        if (midx + 1, sidx + 1) not in bans:
            print(-price)
            break

        heapq.heappush(
            queue, (-mains[i + 1][0] - subs[j][0], i + 1, j, mains[i + 1][1], subs[j][1]))
        heapq.heappush(
            queue, (-mains[i][0] - subs[j + 1][0], i, j + 1, mains[i][1], subs[j + 1][1]))


if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task E - Set Meal
User takedarts
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 1104 Byte
Status TLE
Exec Time 3331 ms
Memory 382512 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 450
Status
AC × 3
AC × 5
TLE × 18
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 03_max_00.txt, 03_max_01.txt, 03_max_02.txt, 03_max_03.txt, 03_max_04.txt, 04_hack_00.txt, 04_hack_01.txt, 04_hack_02.txt, 04_hack_03.txt, 04_hack_04.txt, 04_hack_05.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 130 ms 85640 KiB
00_sample_01.txt AC 128 ms 85340 KiB
00_sample_02.txt AC 127 ms 85524 KiB
01_small_00.txt TLE 3328 ms 355220 KiB
01_small_01.txt TLE 3329 ms 357080 KiB
01_small_02.txt TLE 3328 ms 359424 KiB
01_small_03.txt TLE 3328 ms 358912 KiB
02_random_00.txt TLE 3328 ms 337412 KiB
02_random_01.txt TLE 3328 ms 363756 KiB
02_random_02.txt TLE 3328 ms 340148 KiB
02_random_03.txt TLE 3327 ms 358724 KiB
02_random_04.txt TLE 3331 ms 345588 KiB
03_max_00.txt TLE 3328 ms 348600 KiB
03_max_01.txt TLE 3328 ms 372472 KiB
03_max_02.txt TLE 3328 ms 356176 KiB
03_max_03.txt TLE 3328 ms 355908 KiB
03_max_04.txt TLE 3328 ms 354344 KiB
04_hack_00.txt AC 801 ms 132276 KiB
04_hack_01.txt TLE 3328 ms 341032 KiB
04_hack_02.txt TLE 3327 ms 358740 KiB
04_hack_03.txt TLE 3328 ms 382512 KiB
04_hack_04.txt AC 823 ms 137048 KiB
04_hack_05.txt TLE 3329 ms 373192 KiB