157092025-02-21 23:32:1742Zebra (75 pont)python3Elfogadva 75/75574ms3464 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=list(map(int,input().split()))
 T=list(map(int,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 sol(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,sol(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(sol(len(B),len(J)))

main()
RészfeladatÖsszpontTesztVerdiktIdőMemória
base75/75
1Elfogadva0/017ms3320 KiB
2Elfogadva0/0210ms3372 KiB
3Elfogadva5/516ms3124 KiB
4Elfogadva5/517ms3124 KiB
5Elfogadva5/5100ms3124 KiB
6Elfogadva5/5136ms3240 KiB
7Elfogadva5/5231ms3348 KiB
8Elfogadva5/5175ms3380 KiB
9Elfogadva5/5301ms3412 KiB
10Elfogadva5/5303ms3380 KiB
11Elfogadva5/5391ms3380 KiB
12Elfogadva5/5437ms3380 KiB
13Elfogadva5/5574ms3464 KiB
14Elfogadva5/5307ms3380 KiB
15Elfogadva5/5263ms3380 KiB
16Elfogadva5/5563ms3380 KiB
17Elfogadva5/5509ms3380 KiB