#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ namespace { Int Op(Int x, Int y) { return std::max(x, y); } Int E() { return -INF; } void Solve() { Int n, S, H; Scan(n, S, H); std::vector x(n), y(n), z(n + 1); for (Int i : Rep(n)) { Scan(x[i], y[i], z[i]); } for (Int i : Rev(Rep(n))) { z[i] += z[i + 1]; } std::vector f(n + 1, -INF); f[n] = 0; atcoder::segtree seg(n); for (Int i : Rev(Rep(n))) { f[i] = f[i + 1]; seg.set(i, f[ranges::lower_bound(x, y[i] + H) - x.begin()] - z[i + 1]); Chmax(f[i], z[i] + seg.prod(i, ranges::upper_bound(y, x[i] + S) - y.begin())); } DEBUG(f); Print(f[0]); } } // namespace int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::setprecision(std::numeric_limits::max_digits10); Solve(); } #else // __INCLUDE_LEVEL__ #include #include using Int = int64_t; using Float = double; namespace ranges = std::ranges; namespace views = std::views; inline constexpr auto Rev = views::reverse; inline constexpr auto Map = views::transform; inline constexpr auto Filter = views::filter; constexpr auto Rep(Int l, Int r) { return views::iota(std::min(l, r), r); } constexpr auto Rep(Int n) { return Rep(0, n); } constexpr auto Rep1(Int l, Int r) { return Rep(l, r + 1); } constexpr auto Rep1(Int n) { return Rep(1, n + 1); } constexpr Int Sz(auto&& r) { return static_cast(ranges::size(r)); } template bool Chmin(T& x, U&& y) { return y < x && (x = std::forward(y), true); } template bool Chmax(T& x, U&& y) { return x < y && (x = std::forward(y), true); } inline constexpr Int INF = [] { std::array a; a.fill(0x3f); return std::bit_cast(a); }(); #define DEBUG(...) static_cast(0) template concept Range = ranges::range && !std::convertible_to; template concept TupleLike = std::__is_tuple_like::value && !Range; namespace std { istream& operator>>(istream& is, Range auto&& r) { for (auto&& e : r) { is >> e; } return is; } istream& operator>>(istream& is, TupleLike auto&& t) { return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t); } ostream& operator<<(ostream& os, Range auto&& r) { for (string_view sep = ""; auto&& e : r) { os << exchange(sep, " ") << e; } return os; } ostream& operator<<(ostream& os, TupleLike auto&& t) { const auto f = [&](auto&... xs) -> ostream& { [[maybe_unused]] string_view sep = ""; ((os << exchange(sep, " ") << xs), ...); return os; }; return apply(f, t); } } // namespace std #define DEF_INC_OR_DEC(op) \ auto& operator op(Range auto&& r) { \ for (auto&& e : r) { \ op e; \ } \ return r; \ } \ auto& operator op(TupleLike auto&& t) { \ std::apply([](auto&... xs) { (op xs, ...); }, t); \ return t; \ } DEF_INC_OR_DEC(++) DEF_INC_OR_DEC(--) #undef DEF_INC_OR_DEC void Scan(auto&&... xs) { std::cin >> std::tie(xs...); } void Print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; } template class Fix { public: explicit Fix(F f) : f_(std::move(f)) {} decltype(auto) operator()(auto&&... xs) const { return f_(std::ref(*this), std::forward(xs)...); } private: F f_; }; #endif // __INCLUDE_LEVEL__