pub use __cargo_equip::prelude::*; use algebraic::{algebra, monoid}; use chminmax::chmax; #[allow(unused_imports)] use proconio::{ input, marker::{Bytes, Chars, Usize1}, }; use sliding_window_aggregation::SlidingWindowAggregation; algebra!(M, i64); monoid!(M, -(1 << 60), |&a: &i64, &b: &i64| a.max(b)); fn main() { input! { n: usize, s: i64, h: i64, } let mut a = vec![-2_000_000_000]; let mut b = vec![0]; for _ in 0..n { input! { x: i64, y: i64, z: i64, } if y - x > s { continue; } a.push(x); a.push(y); b.push(0); b.push(z); } for i in 1..b.len() { b[i] += b[i - 1]; } let mut dp1 = vec![0; a.len()]; // dp1[i]: 最後に寝始めたのがiのときの最大値 // let mut dp2 = vec![0; a.len()]; // dp2[i]: 最後に起き上がったのがiのときの最大値 let mut dq = SlidingWindowAggregation::::new(); let mut l1 = 0; let mut l2 = 0; let mut mx = -(1 << 60); for i in 0..a.len() { while l1 < a.len() && a[l1] + h <= a[i] { chmax!(mx, dp1[l1]); l1 += 1; } while l2 < a.len() && a[l2] + s < a[i] { dq.pop_front(); l2 += 1; } chmax!(dp1[i], dq.prod() + b[i]); dq.push_back(mx - b[i]); } println!("{}", dp1.iter().max().unwrap()); } // The following code was expanded by `cargo-equip`. /// # Bundled libraries /// /// - `path+file:///home/junji/code/cprs/crates/algebraic/algebraic#0.1.0` published in **missing** licensed under `CC0-1.0` as `crate::__cargo_equip::crates::algebraic` /// - `path+file:///home/junji/code/cprs/crates/data-structure/sliding-window-aggregation#0.1.0` published in **missing** licensed under `CC0-1.0` as `crate::__cargo_equip::crates::sliding_window_aggregation` /// - `path+file:///home/junji/code/cprs/crates/macros/chminmax#0.1.0` published in **missing** licensed under `CC0-1.0` as `crate::__cargo_equip::crates::chminmax` #[cfg_attr(any(), rustfmt::skip)] #[allow(unused)] mod __cargo_equip { pub(crate) mod crates { pub mod algebraic {pub use crate::__cargo_equip::macros::algebraic::*;pub trait Algebra{type S;}pub trait Act:Algebra{type X;fn act(f:&Self::S,x:&Self::X)->Self::X;}pub trait Monoid:Algebra{fn e()->Self::S;fn op(x:&Self::S,y:&Self::S)->Self::S;}pub trait Group:Monoid{fn inv(x:&Self::S)->Self::S;}pub trait Zero{fn zero()->Self;fn is_zero(&self)->bool;}pub trait One{fn one()->Self;fn is_one(&self)->bool;}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_algebra{($ident:ident,$ty:ty)=>{#[derive(Clone)]enum$ident{}impl$crate::__cargo_equip::crates::algebraic::Algebra for$ident{type S=$ty;}};}macro_rules!algebra{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_algebra!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_act{($ident:ident,$tar:ty,$act:expr)=>{impl$crate::__cargo_equip::crates::algebraic::Act for$ident{type X=$tar;#[inline]fn act(f:&Self::S,x:&Self::X)->Self::X{$act(f,x)}}};}macro_rules!act{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_act!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_monoid{($ident:ident,$e:expr,$op:expr)=>{impl$crate::__cargo_equip::crates::algebraic::Monoid for$ident{#[inline]fn e()->Self::S{$e}#[inline]fn op(x:&Self::S,y:&Self::S)->Self::S{$op(x,y)}}};}macro_rules!monoid{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_monoid!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_group{($ident:ident,$e:expr,$op:expr,$inv:expr)=>{impl$crate::__cargo_equip::crates::algebraic::Monoid for$ident{#[inline]fn e()->Self::S{$e}#[inline]fn op(x:&Self::S,y:&Self::S)->Self::S{$op(x,y)}}impl$crate::__cargo_equip::crates::algebraic::Group for$ident{#[inline]fn inv(x:&Self::S)->Self::S{$inv(x)}}};}macro_rules!group{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_group!{$($tt)*})}macro_rules!impl_zero_one{($($t:ty)*)=>{$(impl$crate::__cargo_equip::crates::algebraic::Zero for$t{fn zero()->Self{0}fn is_zero(&self)->bool{*self==0}}impl$crate::__cargo_equip::crates::algebraic::One for$t{fn one()->Self{1}fn is_one(&self)->bool{*self==1}})*};}impl_zero_one!(usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128);} pub mod sliding_window_aggregation {use crate::__cargo_equip::preludes::sliding_window_aggregation::*;use algebraic::Monoid;pub struct SlidingWindowAggregationwhere M:Monoid,M::S:Clone,{fv:Vec,bv:Vec,fs:Vec,bs:Vec,}implSlidingWindowAggregationwhere M:Monoid,M::S:Clone,{pub fn new()->Self{Self{fv:vec![],bv:vec![],fs:vec![M::e()],bs:vec![M::e()],}}pub fn clear(&mut self){self.fv.clear();self.bv.clear();self.fs.clear();self.fs.push(M::e());self.bs.clear();self.bs.push(M::e());}pub fn len(&self)->usize{self.fv.len()+self.bv.len()}pub fn is_empty(&self)->bool{self.len()==0}pub fn push_back(&mut self,x:M::S){self.bs.push(M::op(self.bs.last().unwrap(),&x));self.bv.push(x);}pub fn push_front(&mut self,x:M::S){self.fs.push(M::op(&x,self.fs.last().unwrap()));self.fv.push(x);}pub fn pop_back(&mut self)->Option{if self.len()==0{None}else if self.len()==1{if self.bv.len()==1{self.bs.pop();self.bv.pop()}else{self.fs.pop();self.fv.pop()}}else{if self.bv.is_empty(){self.rebuild();}self.bs.pop();self.bv.pop()}}pub fn pop_front(&mut self)->Option{if self.len()==0{None}else if self.len()==1{if self.bv.len()==1{self.bs.pop();self.bv.pop()}else{self.fs.pop();self.fv.pop()}}else{if self.fv.is_empty(){self.rebuild();}self.fs.pop();self.fv.pop()}}pub fn prod(&self)->M::S{M::op(self.fs.last().unwrap(),self.bs.last().unwrap())}fn rebuild(&mut self){let mut v=vec![];v.reserve(self.len());v.append(&mut self.fv);v.reverse();v.append(&mut self.bv);self.clear();for x in v[0..v.len()/2].iter().rev(){self.push_front(x.clone());}for x in&v[v.len()/2..v.len()]{self.push_back(x.clone());}}}} pub mod chminmax {pub use crate::__cargo_equip::macros::chminmax::*;#[macro_export]macro_rules!__cargo_equip_macro_def_chminmax_min{($a:expr$(,)*)=>{{$a}};($a:expr,$b:expr$(,)*)=>{{std::cmp::min($a,$b)}};($a:expr,$($rest:expr),+$(,)*)=>{{std::cmp::min($a,$crate::__cargo_equip::crates::chminmax::min!($($rest),+))}};}macro_rules!min{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_chminmax_min!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_chminmax_max{($a:expr$(,)*)=>{{$a}};($a:expr,$b:expr$(,)*)=>{{std::cmp::max($a,$b)}};($a:expr,$($rest:expr),+$(,)*)=>{{std::cmp::max($a,$crate::__cargo_equip::crates::chminmax::max!($($rest),+))}};}macro_rules!max{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_chminmax_max!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_chminmax_chmin{($base:expr,$($cmps:expr),+$(,)*)=>{{let cmp_min=$crate::__cargo_equip::crates::chminmax::min!($($cmps),+);if$base>cmp_min{$base=cmp_min;true}else{false}}};}macro_rules!chmin{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_chminmax_chmin!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_chminmax_chmax{($base:expr,$($cmps:expr),+$(,)*)=>{{let cmp_max=$crate::__cargo_equip::crates::chminmax::max!($($cmps),+);if$base(crate::__cargo_equip_macro_def_chminmax_chmax!{$($tt)*})}} } pub(crate) mod macros { pub mod algebraic {pub use crate::{__cargo_equip_macro_def_algebraic_act as act,__cargo_equip_macro_def_algebraic_algebra as algebra,__cargo_equip_macro_def_algebraic_group as group,__cargo_equip_macro_def_algebraic_monoid as monoid};} pub mod sliding_window_aggregation {} pub mod chminmax {pub use crate::{__cargo_equip_macro_def_chminmax_chmax as chmax,__cargo_equip_macro_def_chminmax_chmin as chmin,__cargo_equip_macro_def_chminmax_max as max,__cargo_equip_macro_def_chminmax_min as min};} } pub(crate) mod prelude {pub use crate::__cargo_equip::crates::*;} mod preludes { pub mod algebraic {} pub mod sliding_window_aggregation {pub(in crate::__cargo_equip)use crate::__cargo_equip::crates::algebraic;} pub mod chminmax {} } }