// これに似てた // https://yukicoder.me/problems/no/1826 #include #include using namespace std; using ll = long long; ll op(ll lhs, ll rhs){ return max(lhs, rhs); } constexpr ll e(){ return -(1ll << 62); } template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; vector x(n), t(n), c(n); vector> a(n); vector ca(n + 1); cin >> t >> x >> c; for(int i = 0; i < n; i++){ a[i] = make_tuple(x[i] + k * t[i], -(x[i] - k * t[i]), c[i]); ca[i] = get<1>(a[i]); } sort(a.begin(), a.end()); sort(ca.begin(), ca.end()); ca.erase(unique(ca.begin(), ca.end()), ca.end()); const int m = ca.size(); atcoder::segtree seg(m); auto pget = [&](ll pos){ return lower_bound(ca.begin(), ca.end(), pos) - ca.begin(); }; seg.set(pget(0), 0); for(auto &&[u, v, c] : a){ if(u < 0) continue; int p = pget(v); seg.set(p, seg.prod(0, p + 1) + c); } cout << seg.all_prod() << '\n'; }