P17653 [IO 2025 #1] Segment Puzzle

Description

During her journey, Hornet sometimes needs to solve various puzzles. For example, to fight a phantom, she must first open the door leading to it. The door has a keyhole of width $W$, and Hornet has $n$ keys. The base of the $i$-th key is an $a_i\times1$ rectangle, with a $b_i\times1$ rectangular bump on top of the base; the distance from the left end of the bump to the left end of the base is $c_i$. It is guaranteed that $a_i\ge b_i+c_i$. The shape of a key is shown in the picture below: :::align{center} ![](https://cdn.luogu.com.cn/upload/image_hosting/cv0i41qb.webp) ::: The bases of the keys can be arranged in a row, end to end, in any order. In addition, any key can be flipped, that is, replaced by its left-right mirror image; in that case $c_i$ becomes $c'_i=a_i-b_i-c_i$. To move on, Hornet needs to fit the bumps of as many keys as possible into the keyhole. These keys fit into the keyhole if the distance between the left end of the leftmost bump and the right end of the rightmost bump does not exceed $W$. In the picture below, three keys can be fitted into the keyhole. :::align{center} ![](https://cdn.luogu.com.cn/upload/image_hosting/t4cdbupt.webp) ::: Help Hornet solve this puzzle!

Input Format

The first line contains two integers $n,W$ — the number of keys and the width of the keyhole, $1\le n\le2\cdot10^5$, $1\le W\le10^9$. Each of the next $n$ lines describes a key: the $i$-th line contains the integers $a_i,b_i,c_i$ — the parameters of the $i$-th key, $1\le b_i\le a_i\le10^9$, $0\le c_i\le a_i-b_i$.

Output Format

On the first line, output an integer $k$ — the maximum number of keys that can be fitted into the keyhole. On the next line, output $k$ nonzero integers in the range from $-n$ to $n$, describing the keys placed into the keyhole in order from left to right. If the next key to be placed is key $i$ and it does not need to be flipped, output $i$; if it needs to be flipped left to right, output $-i$. All used keys must be distinct.

Explanation/Hint

Translated by QwenWork