/*
4.7网易笔试编程第二题暴力dfs解法
第一题求gcd
第四题求矩阵中每个1离它最近的0之间的距离:bfs
*/
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int D = sc.nextInt();
int[] attack = new int[n]; //破防能力
int[] harm = new int[n]; //伤害值
for(int i=0; i<n; i++){
attack[i] = sc.nextInt();
}
for(int i=0; i<n; i++){
harm[i] = sc.nextInt();
}
System.out.println(fun(n, D, attack, harm));
}
}
public static int fun(int n, int D, int[] attack, int[] harm){
//挑战顺序任意,考虑dfs,求每个挑战方案的承受伤害总量
List<List<Integer>> res = new ArrayList<>();
List<Integer> ans = new ArrayList<>();
int[] used = new int[n];
dfs(res, ans, attack, used);
int min = Integer.MAX_VALUE;
for(int i=0; i<res.size(); i++){
List<Integer> list = res.get(i);
//求list顺序下承受总伤害totalHarm
int totalHarm = 0;
int temp = D;
for(int j=0; j<list.size(); j++){
int curIndex = list.get(j);
if(attack[curIndex]>temp){
totalHarm += harm[curIndex];
}else{
temp++;
}
}
min = Math.min(min, totalHarm);
}
return min;
}
public static void dfs(List<List<Integer>> res, List<Integer> ans, int[] attack, int[] used){
if(ans.size()==attack.length){
res.add(new ArrayList<>(ans));
return;
}
for(int i=0; i<attack.length; i++){
if(used[i]==1) continue;
ans.add(i);
used[i] = 1;
dfs(res, ans, attack, used);
ans.remove(ans.size()-1);
used[i] = 0;
}
}
}