96612024-02-23 19:16:44NagyLeoÓvodapython3Futási hiba 46/50330ms67068 KiB
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] = (chosen[i], crying_time[i], 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[merged[i][0]] > 0:
                roles[merged[i][0]] -= 1
                roles_av.discard(merged[i][0])
                res[merged[i][2]] = merged[i][0] + 1
            else:
                cry += merged[i][1]
                leftout.append(merged[i])
        else:
            if merged[i][0] in roles_av:
                roles[merged[i][0]] -= 1
                roles_av.discard(merged[i][0])
                res[merged[i][2]] = 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][2]] = i + 1
        roles[i] -= 1
        leftout.pop()

    index = 0
    for i in leftout:
        while roles[index] == 0:
            index += 1
        res[i[2]] = index + 1
        roles[index] -= 1
    print(cry)
    print(*res)


main()
RészfeladatÖsszpontTesztVerdiktIdőMemória
base46/50
1Elfogadva0/018ms11580 KiB
2Elfogadva0/032ms14724 KiB
3Elfogadva2/218ms11792 KiB
4Elfogadva2/217ms12108 KiB
5Elfogadva2/218ms12496 KiB
6Elfogadva2/217ms12896 KiB
7Elfogadva2/217ms12772 KiB
8Elfogadva2/217ms12940 KiB
9Elfogadva2/217ms12680 KiB
10Elfogadva2/217ms13308 KiB
11Elfogadva2/218ms13188 KiB
12Elfogadva2/217ms13072 KiB
13Elfogadva2/219ms13912 KiB
14Elfogadva3/320ms13744 KiB
15Elfogadva3/352ms20688 KiB
16Elfogadva3/396ms31636 KiB
17Elfogadva3/3145ms34404 KiB
18Elfogadva3/3234ms48716 KiB
19Elfogadva3/3257ms52708 KiB
20Elfogadva3/3291ms52640 KiB
21Elfogadva3/3330ms62912 KiB
22Futási hiba0/4149ms67068 KiB