#include using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; const ll ILL=2167167167167167167; const int INF=2100000000; const int mod=998244353; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} template void vec_out(vector &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} template bool inside(T l,T x,T r){return l<=x&&x using lazy_S = ll; using lazy_F = ll; lazy_S lazy_op(lazy_S l, lazy_S r) { return max(l, r); } lazy_S lazy_e() { return -ILL; } lazy_S mapping(lazy_F l, lazy_S r) { return l + r; } //l(r(x)) lazy_F composition(lazy_F l, lazy_F r) { return l + r; } lazy_F lazy_id(){return 0;} #define lazy_calc lazy_S,lazy_op,lazy_e,lazy_F,mapping,composition,lazy_id void solve(); // CYAN / FREDERIC int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; rep(i, 0, t) solve(); } void solve(){ ll N, S, H; cin >> N >> S >> H; vector X, Y, Z; set s; rep(i, 0, N){ ll x, y, z; cin >> x >> y >> z; if (y - x > S) continue; X.push_back(x); Y.push_back(y); Z.push_back(z); s.insert(x); s.insert(y); } N = X.size(); if (N == 0){ cout << "0\n"; return; } map m; vector v; int len = s.size(); for (auto x : s) m[x] = v.size(), v.push_back(x); vector order(N); rep(i, 0, N) order[i] = i; sort(all(order), [&](int l, int r){ return Y[l] < Y[r]; }); vector inv(N); rep(i, 0, N) inv[order[i]] = i; vector> G(len); rep(i, 0, N){ G[m[X[i]]].push_back(i); } v.push_back(ILL); vector dp(len + 1); atcoder::lazy_segtree seg(len); int j = len; for (int i = len - 1; i >= 0; i--){ for (auto x : G[i]){ seg.apply(m[Y[x]], len, Z[x]); } while (v[j - 1] > S + v[i]){ j--; } /*cout << i << " "<< j << " "<< v[i] << endl; rep(i, 0, len) cout << max((ll)(-1), seg.get(i)) << " "; cout << endl; */ dp[i] = seg.prod(i, j); chmax(dp[i], dp[i + 1]); seg.set(i, dp[LB(v, v[i] + H)]); } cout << dp[0] << "\n"; }