#include #include #define chmin(x,y) (x) = min((x),(y)) #define chmax(x,y) (x) = max((x),(y)) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define vec vector #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back using namespace std; using namespace atcoder; using ll = long long; using ld = long double; const ll mod = 998244353; using mint = modint998244353; const vector dx = {1,0,-1,0}, dy = {0,1,0,-1}; using Graph = vector>>; // using Graph = vector>; // https://betrue12.hateblo.jp/entry/2020/09/23/005940 using S = long long; using F = long long; const S INF = 8e18; const F ID = 8e18; S op(S a, S b){ return std::max(a, b); } S e(){ return -INF; } S mapping(F f, S x){ return (f == ID ? x : f); } F composition(F f, F g){ return (f == ID ? g : f); } F id(){ return ID; } int main(){ // input int N, T; cin >> N >> T; const int M = 200010; vector v(M,0LL); lazy_segtree seg(v); // Graph G(M); // rep(i,M-1) G[i].eb(i+1,0LL); vector L(N),R(N),P(N); rep(i,N){ cin >> L[i] >> R[i] >> P[i]; ++R[i]; seg.apply(L[i],R[i],(ll)P[i]); // pq.push({P[i],L[i],R[i]}); } // solve vector dp(M+1,0LL); // ll now = 0; rep(i,M){ // chmax(dp[i],now); ll x = seg.prod(i,i+1), y = min(M,i+T); if(x) chmax(dp[y],dp[i]+x); chmax(dp[i+1],dp[i]); } // output cout << dp[M] << endl; }