99842024-03-22 23:12:4242Zebra (75 pont)pypy3Elfogadva 75/75287ms111028 KiB
from sys import stdin
input=stdin.readline

def pre(X):
    for i in range(1,len(X)):
        X[i]+=X[i-1]
    return X

memo={}

def main():
    N = int(input())
    C = [int(x) for x in input().split()]
    T = [int(x) for x in input().split()]
    B=[]
    J=[]
    for i in range(N):
        if C[i]==0:
            B.append(T[i])
        else:
            J.append(T[i])
    B.sort()
    J.sort()
    preB=pre(B[:])
    preJ=pre(J[:])

    def solv(x,y):
        if (x,y) in memo:
            return memo[(x,y)]
        last=max(B[x-1],J[y-1])
        res=(x+y)*last-preB[x-1]-preJ[y-1]
        if x==1 or y==1:
            return res
       
        for X in range(1,x):
            for Y in range(1,y):
                last=max(B[x-1],J[y-1])
                res=min(res,solv(X,Y)+last*(x-X+y-Y)-preB[x-1]-preJ[y-1]+preB[X-1]+preJ[Y-1])
        memo[(x,y)]=res
        return res
    
    print(solv(len(B),len(J)))
    
main()
RészfeladatÖsszpontTesztVerdiktIdőMemória
base75/75
1Elfogadva0/059ms93008 KiB
2Elfogadva0/0170ms108748 KiB
3Elfogadva5/548ms92872 KiB
4Elfogadva5/563ms102180 KiB
5Elfogadva5/5119ms105416 KiB
6Elfogadva5/5134ms106252 KiB
7Elfogadva5/5155ms105576 KiB
8Elfogadva5/5122ms107548 KiB
9Elfogadva5/5162ms106400 KiB
10Elfogadva5/5164ms107004 KiB
11Elfogadva5/5231ms109260 KiB
12Elfogadva5/5237ms109824 KiB
13Elfogadva5/5240ms107848 KiB
14Elfogadva5/5190ms109964 KiB
15Elfogadva5/5186ms109180 KiB
16Elfogadva5/5287ms111028 KiB
17Elfogadva5/5222ms108480 KiB