RT,可能假了
#include <algorithm>
#include <iostream>
#include <vector>
#define int long long
using namespace std;
void init_vars();
void solve(int testcase, ...);
signed main(){
#ifdef files
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve(1);
#ifdef files
fclose(stdin); fclose(stdout);
#endif
return 0;
}
int n, k, d[20001], c[20001], s[20001], w[20001], dp[20001], pos[2][20001];
vector<int> vec[20001];
// SGT
struct node{
int l, r, val, lazy;
node operator+(const node &b) const{
node c; c.l = l, c.r = b.r;
c.val = min(val, b.val);
c.lazy = 0;
return c;
}
}tree[20001 << 2];
void build(int l, int r, int p){
if(l == r){
tree[p].l = tree[p].r = l;
tree[p].val = dp[l], tree[p].lazy = 0;
return;
}
int mid = (l + r) >> 1;
build(l, mid, p * 2);
build(mid + 1, r, p * 2 + 1);
tree[p] = tree[p * 2] + tree[p * 2 + 1];
}
void mark(int p, int x){
tree[p].val += x;
tree[p].lazy += x;
}
void tag(int p){
if(tree[p].lazy){
mark(p * 2, tree[p].lazy);
mark(p * 2 + 1, tree[p].lazy);
tree[p].lazy = 0;
}
}
void add(int l, int r, int x, int p){
if(l <= tree[p].l && tree[p].r <= r){
mark(p, x); return;
}
tag(p);
int mid = (tree[p].l + tree[p].r) >> 1;
if(l <= mid) add(l, r, x, p * 2);
if(mid < r) add(l, r, x, p * 2 + 1);
tree[p] = tree[p * 2] + tree[p * 2 + 1];
}
node query(int l, int r, int p){
if(l <= tree[p].l && tree[p].r <= r)
return tree[p];
tag(p);
int mid = (tree[p].l + tree[p].r) >> 1;
if(l <= mid && mid < r)
return query(l, r, p * 2) + query(l, r, p * 2 + 1);
else if(l <= mid)
return query(l, r, p * 2);
else
return query(l, r, p * 2 + 1);
}
void init_vars(){
// type your initiating code...
}
void solve(int testcase, ...){
init_vars();
cin >> n >> k;
for(int i = 2; i <= n; i++)
cin >> d[i];
for(int i = 1; i <= n; i++)
cin >> c[i];
for(int i = 1; i <= n; i++)
cin >> s[i];
for(int i = 1; i <= n; i++)
cin >> w[i];
for(int i = 1; i <= n; i++){
dp[i] = dp[i - 1] + w[i];
pos[0][i] = lower_bound(d + 1, d + n + 1, d[i] - s[i]) - d;
pos[1][i] = upper_bound(d + 1, d + n + 1, d[i] + s[i]) - d - 1;
vec[pos[1][i]].push_back(i);
}
int ans = dp[n];
for(int i = 1; i <= k; i++){
build(0, n, 1);
for(int j = 1; j <= n; j++){
dp[j] = query(0, j - 1, 1).val + c[j];
for(auto x : vec[j])
add(0, pos[0][x] - 1, w[x], 1);
}
ans = min(ans, dp[n]);
}
cout << ans << endl;
}
/*
* things to check
* 1. CZY's brain
* 2. ...
**/
/*
* something to think about
* 1. how to fix my brain?
**/
/*
########## ############ ##### #####
#### ##### #### ####
#### ##### #### ####
#### ########## #### ####
#### ##### #####
#### ##### #####
#### ##### #####
########### ############# #####
*/