There's a sticker album very popular among the children of Pavussulandia. To fill the album, they need to find $$$M$$$ distinct stickers with identifiers from $$$1$$$ to $$$M$$$. The stickers are sold in packs, and there are $$$N$$$ packs available for purchase. Each pack $$$i$$$, such that $$$1 \leq i \leq N$$$, has $$$K_i$$$ stickers and costs $$$V_i$$$ reais.
In the store, the stickers are arranged on a shelf in order, and you have to choose an interval $$$[i, j]$$$ and buy all the packs from $$$i$$$ to $$$j$$$ (including $$$i$$$ and $$$j$$$). Since the stickers are highly sought after, you can only make one interval choice.
Little Biel is excited to fill his album; however, his family doesn't have much money. With that, he needs your help to spend as little as possible and complete the album. If there is no answer, you must inform Biel, preventing him from unnecessarily wasting money.
The first line contains the integers $$$N$$$ and $$$M$$$ $$$(1 \leq N,M \leq 2 \cdot 10^5)$$$, where $$$N$$$ is the number of packs and $$$M$$$ is the number of distinct stickers.
The next $$$N$$$ lines are formatted as:
Where $$$K_i$$$ $$$(1 \leq K_i \leq M)$$$ is the number of stickers in pack $$$i$$$ $$$(1 \leq i \leq N)$$$, $$$V_i$$$ $$$(1 \leq V_i \leq 10^9)$$$ is the price of pack $$$i$$$, and $$$F_{i,j}$$$ $$$(1 \leq F_{i,j} \leq M)$$$ is the identifier of the sticker.
Note that the same pack may contain duplicate stickers. And it's guaranteed that the sum of all the $$$K_i$$$ quantities of stickers from all the $$$N$$$ packs does not exceed $$$2 \cdot 10^5$$$.
Your program should print $$$-1$$$ if there is no valid interval. If there is, print two lines. The first one with the minimum total spent and the second with the values $$$i$$$ and $$$j$$$ of the chosen interval. In the event of multiple answers, print any of them.
4 5 1 2 5 2 4 1 5 3 5 4 2 1 2 1 3 1
10 2 4
4 5 1 1 5 2 1 1 5 2 1 2 1 2 1 3 1
-1
1 4 4 10 1 2 3 4
10 1 1
In the first example, we have $$$5$$$ distinct stickers (numbered from $$$1$$$ to $$$5$$$) and the following packs:
With the choice of packs in the interval $$$[2,4]$$$, Biel will pay a total of $$$4 + 5 + 1 = 10$$$ and will obtain all $$$5$$$ stickers. It can be shown that this is the least expensive choice to obtain all the stickers.