88302024-01-31 18:30:08NagyLeoBányász RPG (40 pont)python3Elfogadva 40/40232ms51868 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]])

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

    while all1 != experience:
        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())
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/017ms11292 KiB
2Elfogadva0/043ms18180 KiB
3Elfogadva2/217ms11596 KiB
4Elfogadva2/218ms11972 KiB
5Elfogadva2/234ms16996 KiB
6Elfogadva2/259ms23056 KiB
7Elfogadva2/223ms13656 KiB
8Elfogadva2/225ms14492 KiB
9Elfogadva3/317ms12472 KiB
10Elfogadva3/317ms12684 KiB
11Elfogadva3/317ms12884 KiB
12Elfogadva3/318ms13084 KiB
13Elfogadva4/418ms13340 KiB
14Elfogadva4/418ms13400 KiB
15Elfogadva2/2111ms34268 KiB
16Elfogadva2/2153ms42272 KiB
17Elfogadva2/2115ms35988 KiB
18Elfogadva2/2232ms51868 KiB