94462024-02-21 19:37:03petergalambosBányász RPG (40 pont)python3Accepted 40/40207ms57704 KiB
from sys import stdin,stdout

def main():
    N = int(input())
    R = [(int(i),index) for index,i in enumerate(stdin.readline().split(),start = 1)]
    R.sort()
    A = [0]+[int(i) for i in stdin.readline().split()]

    S = 0
    T = 0
    draga = N-1
    olcso = 0
    

    while draga >= olcso:
        if T < R[olcso][0]:
            mini = min(R[olcso][0]-T,A[R[draga][1]])
            S += mini*2
            T += mini
            A[R[draga][1]] -= mini
            if A[R[draga][1]] == 0:
                draga -= 1
        else:
            db = A[R[olcso][1]]
            S += db
            T += db
            olcso += 1
    stdout.write(str(S))
    
main()
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/017ms11364 KiB
2Accepted0/043ms19656 KiB
3Accepted2/218ms11764 KiB
4Accepted2/219ms12384 KiB
5Accepted2/234ms18588 KiB
6Accepted2/254ms25360 KiB
7Accepted2/223ms14144 KiB
8Accepted2/224ms15108 KiB
9Accepted3/317ms12964 KiB
10Accepted3/317ms12968 KiB
11Accepted3/317ms12888 KiB
12Accepted3/317ms13460 KiB
13Accepted4/419ms13656 KiB
14Accepted4/418ms13384 KiB
15Accepted2/2118ms36020 KiB
16Accepted2/2152ms47120 KiB
17Accepted2/2120ms38068 KiB
18Accepted2/2207ms57704 KiB