213932026-01-12 23:58:41algoproBányász RPG (40 pont)pypy3Runtime error 36/40143ms32000 KiB
# UUID: 167d12e3-9e01-48f6-a073-ca246c558d84

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)
    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/039ms19440 KiB
2Accepted0/075ms22936 KiB
3Accepted2/243ms19536 KiB
4Accepted2/243ms21232 KiB
5Accepted2/256ms22760 KiB
6Accepted2/261ms25064 KiB
7Accepted2/259ms21756 KiB
8Accepted2/263ms21788 KiB
9Accepted3/345ms19436 KiB
10Accepted3/343ms19460 KiB
11Accepted3/339ms19640 KiB
12Accepted3/343ms21212 KiB
13Accepted4/450ms21164 KiB
14Accepted4/443ms21116 KiB
15Accepted2/2143ms28512 KiB
16Runtime error0/268ms32000 KiB
17Accepted2/2142ms29168 KiB
18Runtime error0/268ms32000 KiB