96632024-02-23 19:25:26NagyLeoÓvodapython3Futási hiba 46/50344ms67712 KiB
from sys import stdin, stdout
input=stdin.readline

def main():
    N, K = map(int, input().split())
    roles = list(map(int, input().split()))  # K hosszu
    chosen = list(map(lambda x: int(x) - 1, input().split()))  # N hosszú
    crying_time = list(map(int, input().split()))  # N hosszu
    merged = [0] * N
    leftout = []
    roles_av = set(range(K))

    for i in range(N):
        merged[i] = (i, crying_time[i])

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

    cry = 0
    res = [-1] * N

    for i in range(N):
        # print(i,merged[i],res,roles_av,leftout, roles,len(roles_av), N-i-len(leftout))
        if len(roles_av) < N - i + len(leftout):
            if roles[chosen[merged[i][0]]] > 0:
                roles[chosen[merged[i][0]]] -= 1
                roles_av.discard(chosen[merged[i][0]])
                res[merged[i][0]] = chosen[merged[i][0]] + 1
            else:
                cry += merged[i][1]
                leftout.append(merged[i])
        else:
            if chosen[merged[i][0]] in roles_av:
                roles[chosen[merged[i][0]]] -= 1
                roles_av.discard(chosen[merged[i][0]])
                res[merged[i][0]] = chosen[merged[i][0]] + 1
            else:
                cry += merged[i][1]
                leftout.append(merged[i])
        # rint('--------',i,merged[i],res,roles_av,leftout, roles)

    # print(len(roles_av),len(leftout))

    for i in roles_av:
        res[leftout[-1][0]] = i + 1
        roles[i] -= 1
        leftout.pop()

    index = 0
    for i in leftout:
        while roles[index] == 0:
            index += 1
        res[i[0]] = index + 1
        roles[index] -= 1
    stdout.write(str(cry))
    print()
    for i in range(N):
        stdout.write(str(f"{res[i]} "))


main()
RészfeladatÖsszpontTesztVerdiktIdőMemória
base46/50
1Elfogadva0/017ms11696 KiB
2Elfogadva0/032ms14664 KiB
3Elfogadva2/217ms12088 KiB
4Elfogadva2/217ms12216 KiB
5Elfogadva2/218ms12660 KiB
6Elfogadva2/217ms12608 KiB
7Elfogadva2/217ms12696 KiB
8Elfogadva2/217ms13332 KiB
9Elfogadva2/217ms13048 KiB
10Elfogadva2/217ms13068 KiB
11Elfogadva2/217ms13056 KiB
12Elfogadva2/217ms13284 KiB
13Elfogadva2/219ms13816 KiB
14Elfogadva3/319ms13848 KiB
15Elfogadva3/352ms20572 KiB
16Elfogadva3/398ms30968 KiB
17Elfogadva3/3149ms35084 KiB
18Elfogadva3/3222ms48336 KiB
19Elfogadva3/3268ms52576 KiB
20Elfogadva3/3310ms51912 KiB
21Elfogadva3/3344ms62860 KiB
22Futási hiba0/4136ms67712 KiB