#include using namespace std; template struct SegTree{ using FX = function; // X•X -> X となる関数の型 int n; FX fx; const X ex; vector dat; SegTree(int n_, const FX &fx_, const X &ex_) : n(), fx(fx_), ex(ex_){ int x = 1; while(n_ > x){ x *= 2; } n = x; dat.assign(n * 2, ex); } X get(int i) const { return dat[i + n]; } void set(int i, const X &x){ dat[i + n] = x; } void build(){ for(int k = n - 1; k >= 1; k--) dat[k] = fx(dat[k * 2], dat[k * 2 + 1]); } void update(int i, const X &x){ i += n; dat[i] = x; while(i > 0){ i >>= 1; // parent dat[i] = fx(dat[i * 2], dat[i * 2 + 1]); } } X query(int a, int b){ X vl = ex; X vr = ex; int l = a + n; int r = b + n; while(l < r){ if(l & 1) vl = fx(vl, dat[l++]); if(r & 1) vr = fx(dat[--r], vr); l >>= 1; r >>= 1; } return fx(vl, vr); } X operator [](int i) const { return dat[i + n]; } }; template struct compress{ vector sorted; vector compressed; compress(const vector &vec){ int n = vec.size(); compressed.resize(n); for(T x : vec){ sorted.emplace_back(x); } sort(sorted.begin(), sorted.end()); sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end()); for(int i = 0; i < n; ++i){ compressed[i] = lower_bound(sorted.begin(), sorted.end(), vec[i]) - sorted.begin(); } } int get(const T &x) const{ return lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin(); } T inv(const int x) const{ return sorted[x]; } size_t size() const{ return sorted.size(); } vector getCompressed() const{ return compressed; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; long long k; cin >> n >> k; assert(n >= 1 && n <= 200000); assert(k >= 1 && k <= 1000000000LL); vector t(n), x(n), c(n); for(int i = 0; i < n; i++){ cin >> t[i]; assert(t[i] >= 1 && t[i] <= 1000000000LL); } for(int i = 0; i < n; i++){ cin >> x[i]; assert(abs(x[i]) <= 1000000000LL); } for(int i = 0; i < n; i++){ cin >> c[i]; assert(c[i] >= 1 && c[i] <= 1000000000LL); } set> s; for(int i = 0; i < n; i++){ s.emplace(t[i], x[i]); } assert((int) s.size() == n); vector a(n), b(n); for(int i = 0; i < n; i++){ a[i] = k * t[i] + x[i]; b[i] = k * t[i] - x[i]; } compress compa(a), compb(b); int sizea = compa.size(), sizeb = compb.size(); SegTree seg(sizea, [](long long a, long long b){ return max(a, b); }, 0); vector>> v(sizeb); for(int i = 0; i < n; i++){ v[compb.get(b[i])].emplace_back(compa.get(a[i]), c[i]); } for(int i = 0; i < sizeb; i++){ sort(v[i].begin(), v[i].end()); } for(int i = 0; i < sizeb; i++){ for(auto [a, c] : v[i]){ long long val = seg.query(0, a + 1); seg.update(a, val + c); } } cout << seg.query(0, sizea) << "\n"; }