213872026-01-12 22:54:43algoproBányász RPG (40 pont)pypy3Runtime error 36/40141ms32000 KiB
# UUID: c6768743-5709-4f88-ae49-433c3c8f1389
def solvx():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    idx = list(range(N))
    idx.sort(key=lambda i: A[i])

    total_second = sum(B[i] for i in idx)
    ketpercesek = 0

    running_prefix = total_second

    for pos in range(N - 1, -1, -1):
        i = idx[pos]

        running_prefix -= B[i]

        if A[i] > ketpercesek + running_prefix:
            need = A[i] - (ketpercesek + running_prefix)
            if need < B[i]:
                ketpercesek += need
            else:
                ketpercesek += B[i]

    print(ketpercesek + total_second)

solvx()
SubtaskSumTestVerdictTimeMemory
base36/40
1Accepted0/041ms19408 KiB
2Accepted0/081ms22852 KiB
3Accepted2/248ms19432 KiB
4Accepted2/246ms21228 KiB
5Accepted2/271ms22836 KiB
6Accepted2/271ms25912 KiB
7Accepted2/261ms22212 KiB
8Accepted2/268ms22160 KiB
9Accepted3/350ms19508 KiB
10Accepted3/348ms19520 KiB
11Accepted3/350ms19580 KiB
12Accepted3/346ms21272 KiB
13Accepted4/448ms21336 KiB
14Accepted4/452ms21144 KiB
15Accepted2/2138ms28576 KiB
16Runtime error0/285ms32000 KiB
17Accepted2/2141ms28932 KiB
18Runtime error0/286ms32000 KiB