#include using namespace std; constexpr int SIZE = 2 << 17; long long dp[SIZE]; vector> PR[SIZE]; priority_queue> pq; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, T; cin >> N >> T; while (N--) { int l, r, p; cin >> l >> r >> p; PR[l + 1].emplace_back(p, r + 1); } pq.push({0, SIZE}); for (int i = 1; i < SIZE; i++) { for (auto [p, r] : PR[i]) { pq.push({p, r}); } while (pq.top().second < i) pq.pop(); dp[i] = max(dp[i - 1], dp[max(0, i - T)] + pq.top().first); } cout << dp[SIZE - 1] << endl; }