#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) template bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; // template atcoder segtree using S = ll; S op(S a, S b){ return a + b; } S e(){ return 0; } using segtree = atcoder::segtree; int main(){ ll n,s,h; cin>>n>>s>>h; vector x(n),y(n),z(n); rep(i,0,n) cin>>x.at(i)>>y.at(i)>>z.at(i); map> el; vector al={0}; rep(i,0,n){ al.push_back(x.at(i)); al.push_back(y.at(i)); el[x.at(i)].push_back(y.at(i)); } sort(al.begin(),al.end()); al.erase(unique(al.begin(),al.end()),al.end()); int m=al.size(); auto get_idx=[&](ll a){ return lower_bound(al.begin(),al.end(),a)-al.begin(); }; auto get_uidx=[&](ll a){ return upper_bound(al.begin(),al.end(),a)-al.begin(); }; segtree seg(m); rep(i,0,n){ seg.set(get_idx(y.at(i)),z.at(i)); } vector dp(m+1,0); rep(i,0,m){ ll nw=al.at(i); ll nx=get_idx(nw+s+h); chmax(dp.at(nx),dp.at(i)+seg.prod(0,get_uidx(nw+s))); if(el.count(nw)){ for(auto y:el.at(nw)){ seg.set(get_idx(y),0); } } chmax(dp.at(i+1),dp.at(i)); } cout<