213882026-01-12 22:57:04algoproBányász RPG (40 pont)pypy3Runtime error 36/40143ms32000 KiB
# UUID: e10217c4-16a8-4931-a52e-ab61375f35d4
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/039ms19452 KiB
2Accepted0/079ms22984 KiB
3Accepted2/243ms19628 KiB
4Accepted2/243ms21416 KiB
5Accepted2/264ms22892 KiB
6Accepted2/261ms25056 KiB
7Accepted2/250ms21704 KiB
8Accepted2/261ms21748 KiB
9Accepted3/339ms19436 KiB
10Accepted3/345ms19548 KiB
11Accepted3/345ms19512 KiB
12Accepted3/343ms21212 KiB
13Accepted4/450ms21232 KiB
14Accepted4/443ms21172 KiB
15Accepted2/2128ms28508 KiB
16Runtime error0/279ms32000 KiB
17Accepted2/2143ms28932 KiB
18Runtime error0/279ms32000 KiB