88312024-01-31 18:34:07NagyLeoBányász RPG (40 pont)python3Accepted 40/40230ms51844 KiB
def main():
    N = int(input())
    exp = list(map(int, input().split()))
    mat = list(map(int, input().split()))

    time = 0
    whole = []
    experience = 0
    cheapest = N - 1
    expensive = 0

    for i in range(0, N):
        whole.append([mat[i], exp[i]])

    whole.sort(key=lambda x: -x[1])

    while expensive <= cheapest:
        if whole[cheapest][1] <= experience:
            time += whole[cheapest][0]
            experience += whole[cheapest][0]
            cheapest -= 1
        else:
            minimum = min(whole[expensive][0], whole[cheapest][1] - experience)
            time += minimum * 2
            experience += minimum
            whole[expensive][0] -= minimum
            if whole[expensive][0] == 0:
                expensive += 1

    return time


print(main())
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/017ms11220 KiB
2Accepted0/043ms18208 KiB
3Accepted2/217ms11452 KiB
4Accepted2/218ms11892 KiB
5Accepted2/234ms17100 KiB
6Accepted2/256ms23260 KiB
7Accepted2/223ms14016 KiB
8Accepted2/224ms14344 KiB
9Accepted3/317ms12192 KiB
10Accepted3/317ms12624 KiB
11Accepted3/318ms13096 KiB
12Accepted3/317ms13088 KiB
13Accepted4/417ms13332 KiB
14Accepted4/417ms13432 KiB
15Accepted2/2112ms34348 KiB
16Accepted2/2156ms43036 KiB
17Accepted2/2115ms36420 KiB
18Accepted2/2230ms51844 KiB