88322024-01-31 18:38:57NagyLeoBányász RPG (40 pont)python3Accepted 40/40194ms48808 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
            whole[expensive] = (whole[expensive][0] - minimum, whole[expensive][1])
            if whole[expensive][0] == 0:
                expensive += 1

    return time


print(main())
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/017ms11400 KiB
2Accepted0/041ms17828 KiB
3Accepted2/217ms11528 KiB
4Accepted2/218ms12244 KiB
5Accepted2/232ms16920 KiB
6Accepted2/254ms22628 KiB
7Accepted2/221ms13600 KiB
8Accepted2/224ms14372 KiB
9Accepted3/317ms12604 KiB
10Accepted3/317ms12772 KiB
11Accepted3/317ms12744 KiB
12Accepted3/317ms12840 KiB
13Accepted4/417ms12692 KiB
14Accepted4/417ms12940 KiB
15Accepted2/298ms32348 KiB
16Accepted2/2130ms39896 KiB
17Accepted2/2107ms34156 KiB
18Accepted2/2194ms48808 KiB