#P3537. The Heist in the Cloakroom

    ID: 16791 Type: Default 1000ms 256MiB

The Heist in the Cloakroom

The Heist in the Cloakroom

The annual rich citizen's reunion is taking place in Byteotia. The wealthy guests leave their expensive items such as coats, jackets, and umbrellas in a cloakroom when they attend the banquet. Unfortunately, a gang of Byteotian thieves plans to steal some of these items. Each item has a value, a drop‐off time, and a retrieval time. An item dropped off exactly at the start time of a robbery can be stolen, but in order for a robbery plan to be feasible, the thieves must select items that sum up exactly to a target value \(k_j\) such that, for every stolen item with retrieval time \(r_i\), it holds that \(r_i > m_j+s_j\), where \(m_j\) is the robbery start time and \(s_j\) is the duration of the robbery.

A plan is feasible if and only if at time \(m_j\) it is possible to choose a subset of items (with drop-off time \(\le m_j\)) which have a total value exactly \(k_j\) and such that each chosen item has a retrieval time strictly greater than \(m_j+s_j\). If no such subset exists, the plan is infeasible.

Given the details of each item and several robbery plans, your task is to determine for each plan whether the thieves can successfully execute it without being disturbed by the owners coming to collect their items.

inputFormat

The input begins with two integers (n) and (q), representing the number of items and the number of robbery plans, respectively. (n) lines follow, each containing three integers: (v), (d), and (r), where (v) is the value of an item, (d) is the drop-off time, and (r) is the retrieval time of that item. Then (q) lines follow, each with three integers (m_j), (k_j), and (s_j) denoting the start time of the robbery, the exact total value that must be stolen, and the duration of the heist, respectively.

Note that an item dropped off at time (m_j) is available for theft. However, an item can only be stolen if its retrieval time satisfies (r > m_j+s_j).

outputFormat

For each robbery plan, output a single line containing “Yes” if the plan is feasible, or “No” if it is not.

sample

3 3
5 1 10
3 2 7
2 3 6
2 5 3
3 5 3
3 8 3
Yes

Yes Yes

</p>