96622024-02-23 19:17:24NagyLeoÓvodapypy3Runtime error 28/50118ms100912 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()
SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/048ms76904 KiB
2Accepted0/081ms90828 KiB
3Accepted2/241ms78088 KiB
4Accepted2/246ms78052 KiB
5Accepted2/248ms78772 KiB
6Accepted2/248ms78120 KiB
7Accepted2/243ms78660 KiB
8Accepted2/239ms78744 KiB
9Accepted2/248ms79044 KiB
10Accepted2/248ms79272 KiB
11Accepted2/250ms79712 KiB
12Accepted2/243ms79476 KiB
13Accepted2/263ms88928 KiB
14Accepted3/364ms89112 KiB
15Accepted3/3118ms99832 KiB
16Runtime error0/376ms100912 KiB
17Runtime error0/368ms100424 KiB
18Runtime error0/367ms100012 KiB
19Runtime error0/364ms100644 KiB
20Runtime error0/368ms95600 KiB
21Runtime error0/364ms100188 KiB
22Runtime error0/463ms95256 KiB