ls

include<bits/stdc++.h>

using namespace std;
const int N=20010,K=110;;
int n,k;
int f[K][N];
struct data{
int d,c,s,w;
data(int d=0):d(d){c=s=w=0;}
}a[N];
bool operator<(const data&a,const data&b){
return a.d+a.s<b.d+b.s;
}
int solve1(int d){
int l=0,r=n,ans=0;
while(l<=r){
int mid=(l+r)/2;
if(a[mid].d+a[mid].s<d)ans=mid,l=mid+1;
else r=mid-1;
}
return ans;
}
int solve2(int d){
int l=1,r=n,ans=n;
while(l<=r){
int mid=(l+r)/2;
if(a[mid].d-a[mid].s<=d)ans=mid,l=mid+1;
else r=mid-1;
}
return ans;
}
int main(){
// freopen("1.in","r",stdin);
cin>>n>>k;
for(int i=2;i<=n;++i)scanf("%d",&a[i].d);
for(int i=1;i<=n;++i)scanf("%d",&a[i].c);
for(int i=1;i<=n;++i)scanf("%d",&a[i].s);
for(int i=1;i<=n;++i)scanf("%d",&a[i].w);
sort(a+1,a+n+1);
memset(f,0x3f,sizeof f);
f[0][0]=0;
for(int i=1;i<=n;++i){
for(int j=0;j<=k;++j){
f[i][j]=min(f[i][j],f[i-1][j]+a[i].w);
if(j){
int p=solve1(a[i].d);
for(int k=p;k<i;++k){
f[i][j]=min(f[i][j],f[k][j-1]+a[i].c);
}
p=solve2(a[i].d);
for(int k=i+1;k<=p;++k){
f[k][j]=min(f[k][j],f[i][j]);
}
}
}
}
int ans=0x3f3f3f3f;
for(int i=0;i<=k;++i){
ans=min(ans,f[n][i]);
}
cout<<ans<<endl;
}

posted @ 2020-07-29 15:37  整理者  阅读(321)  评论(0编辑  收藏  举报