1 program treapmod;
2 uses math;
3 const maxn=100;
4 maxnum=1000000000;
5 type
6 ty=record
7 s,q,f:longint;
8 end;
9 var
10 n,k,i:longint;
11 a:array[0..maxn] of ty;
12 s:array[0..maxn] of longint;
13 f:array[0..maxn,0..maxn,0..maxn] of longint;
14 //==================
15 procedure sort(l,r,k:longint);
16 var
17 i,j,m:longint;
18 t:ty;
19 begin
20 i:=l; j:=r;
21 if k=1 then m:=a[(l+r) >> 1].q else m:=a[(l+r) >> 1].s;
22 repeat
23 if k=1 then
24 begin
25 while a[i].q<m do inc(i);
26 while a[j].q>m do dec(j);
27 end else
28 begin
29 while a[i].s<m do inc(i);
30 while a[j].s>m do dec(j);
31 end;
32 if i<=j then
33 begin
34 t:=a[i]; a[i]:=a[j]; a[j]:=t;
35 inc(i); dec(j);
36 end;
37 until i>j;
38 if i<r then sort(i,r,k);
39 if j>l then sort(l,j,k);
40 end;
41 //==================
42 function find(i,j,w:longint):longint;
43 var
44 x:longint;
45 begin
46 if i>j then exit(0);
47 if f[i,j,w]>-1 then exit(f[i,j,w]);
48 f[i,j,w]:=maxnum;
49 for x:=i to j do
50 begin
51 if a[x].q>=w then
52 f[i,j,w]:=min(f[i,j,w],find(i,x-1,a[x].q)+find(x+1,j,a[x].q)+s[j]-s[i-1]);
53 f[i,j,w]:=min(f[i,j,w],find(i,x-1,w)+find(x+1,j,w)+s[j]-s[i-1]+k);
54 end;
55 exit(f[i,j,w]);
56 end;
57 //==================
58 procedure main;
59 begin
60 fillchar(f,sizeof(f),255);
61 writeln(find(1,n,0));
62 end;
63 //==================
64 begin
65 assign(input,'treapmod.in'); reset(input);
66 assign(output,'treapmod.out'); rewrite(output);
67 read(n,k);
68 for i:=1 to n do read(a[i].s);
69 for i:=1 to n do read(a[i].q);
70 for i:=1 to n do read(a[i].f);
71 sort(1,n,1);
72 for i:=1 to n do a[i].q:=i;
73 sort(1,n,2);
74 for i:=1 to n do s[i]:=s[i-1]+a[i].f;
75 main;
76 close(input); close(output);
77 end.