#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 = 4 << 17; atcoder::lazy_segtree seg(SIZE); for (auto [p, l, r] : PLR) { seg.apply(l, r + 1, p); } vector dp(SIZE + 1, 0); for (int i = T; i <= SIZE; i++) { dp[i] = max(dp[i - T] + seg.get(i - T), dp[i - 1]); } cout << dp[SIZE] << endl; }