96642024-02-23 19:37:04pythonÓvodapython3Wrong answer 28/50319ms67420 KiB
# O(NlogN?) moho

from sys import stdin, stdout
input=stdin.readline

from math import gcd

def solv():
    N,K = [int(x) for x in input().split()]
    maxi = [int(x) for x in input().split()]
    szerep = [int(x)-1 for x in input().split()]
    sir = [(int(x),index) for index,x in enumerate(input().split())]
    sir.sort(reverse=True)
    #print(sir)
    szerep_set=set(szerep)
    not_choosen=set()
    for i in range(1,K):
        if i not in szerep_set:
            not_choosen.add(i)
    #print(not_choosen)
    res=0
    lista=[0]*N
    done=set()
    sirnifog=[]
    for i in range(len(sir)):
        #print(sir[i],lista,len(done),len(not_choosen),len(sirnifog))
        s,index=sir[i]
        #if len(done)+len(not_choosen)+len(sirnifog)==N and len(not_choosen)>len(sirnifog):
        if K-len(done)-len(sirnifog)==N-i:
            x=not_choosen.pop()
            lista[index]=x
            done.add(index)
            res+=s
        elif maxi[szerep[index]]>0:
            maxi[szerep[index]]-=1
            lista[index]=szerep[index]
            done.add(index)
        else:
            sirnifog.append(index)
            res+=s
    index=0
    while sirnifog:
        x=sirnifog.pop()
        if not_choosen:
            y=not_choosen.pop()
            maxi[y]-=1
            lista[x]=y
        else:
            while maxi[index]==0:
                index+=1
            maxi[index]-=1
            lista[x]=index
    print(res)
    print(*[x+1 for x in lista])

    return

solv()
SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/018ms11476 KiB
2Accepted0/032ms15588 KiB
3Accepted2/218ms12000 KiB
4Accepted2/218ms12168 KiB
5Accepted2/217ms12172 KiB
6Accepted2/217ms12328 KiB
7Wrong answer0/217ms12188 KiB
8Accepted2/217ms12556 KiB
9Runtime error0/217ms12724 KiB
10Accepted2/217ms12584 KiB
11Accepted2/217ms12976 KiB
12Accepted2/217ms12928 KiB
13Wrong answer0/219ms13904 KiB
14Accepted3/319ms13440 KiB
15Wrong answer0/354ms21852 KiB
16Wrong answer0/398ms31208 KiB
17Accepted3/3149ms42424 KiB
18Wrong answer0/3224ms55936 KiB
19Accepted3/3300ms63164 KiB
20Accepted3/3319ms56440 KiB
21Runtime error0/3273ms67420 KiB
22Runtime error0/4217ms67412 KiB