202092026-01-04 23:35:41algoproBányász RPG (40 pont)pypy3Runtime error 32/4076ms32000 KiB
# UUID: f9ffc765-c41c-4ab9-929f-7044b00339d2
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

print(time)
SubtaskSumTestVerdictTimeMemory
base32/40
1Accepted0/043ms19632 KiB
2Accepted0/074ms24620 KiB
3Accepted2/239ms19628 KiB
4Accepted2/246ms21344 KiB
5Accepted2/259ms24296 KiB
6Accepted2/276ms26088 KiB
7Accepted2/252ms21968 KiB
8Accepted2/261ms22528 KiB
9Accepted3/346ms19500 KiB
10Accepted3/346ms19652 KiB
11Accepted3/339ms19492 KiB
12Accepted3/343ms21172 KiB
13Accepted4/454ms21544 KiB
14Accepted4/450ms21216 KiB
15Runtime error0/265ms32000 KiB
16Runtime error0/264ms32000 KiB
17Runtime error0/274ms32000 KiB
18Runtime error0/267ms32000 KiB