function Main(INPUT){ const input=INPUT.split("\n"); const [N,T]=input[0].split(" ").map(_=>parseInt(_)); class SegTree{ tree=[]; n=1; constructor(N){ while(this.n=u || r<=b){ return; } else if(l<=b && r>=u){ this.tree[now]=Math.max(this.tree[now], x); } else{ this.update(x,l,r,b,Math.floor((b+u)/2), now*2+1); this.update(x,l,r,Math.floor((b+u)/2),u,now*2+2); } } query(x,l,r){ this.update(x,l,r,0,this.n,0); } get(i){ let now=this.n-1+i; let ret=this.tree[now]; while(now>0){ now=Math.floor((now-1)/2); ret=Math.max(ret, this.tree[now]); } return ret; } } const st = new SegTree(200005); for(let i=0;iparseInt(_)); st.query(P,L,R+1); } const dp=initArray(200003, 0); for(let i=0;i<200001;i++){ dp[i+1]=Math.max(dp[i+1], dp[i]); dp[Math.min(i+T, 200001)]=Math.max(dp[Math.min(i+T, 200001)], dp[i]+st.get(i)); } console.log(dp[200001]); } Main(require("fs").readFileSync("/dev/stdin", "utf8")); function initArray(numberOfItems, initiationOfItem){ return new Array(numberOfItems).fill().map(_=>structuredClone(initiationOfItem)); }