#include #include using namespace std; 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 0; } 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() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, T; cin >> N >> T; vector> PLR(N); for (auto& row : PLR) { cin >> row[1] >> row[2] >> row[0]; } sort(PLR.begin(), PLR.end()); const int SIZE = 3 << 17; atcoder::lazy_segtree seg(SIZE); for (auto [p, l, r] : PLR) { seg.apply(l, r + 1, p); } vector dp(SIZE + 1, 0); long long ans = 0LL; for (int i = 0; i < SIZE - T + 1; i++) { dp[i + T] = max(dp[i + T], dp[i] + seg.get(i)); ans = max(ans, dp[i + T]); } cout << ans << endl; }