#P13848. [CERC 2023] Drying Laundry

[CERC 2023] Drying Laundry

题目描述

Harry the Beaver runs a hotel and has to wash bed sheets every Sunday night for the next QQ weeks until the tourist season ends. On week jj, he has NN freshly washed bed sheets that he wants to dry by hanging them on two parallel clotheslines of length LjL_j each. The sheets can be hung next to each other but must not overlap. Each sheet is did_i units wide and rather long, therefore he will always orient it so that it will take up did_i units of the line when hung to dry. The sheets have different drying times that are not related to their sizes because of different materials. Thus, the ii-th sheet needs tislowt_i^{\text{slow}} minutes to dry. However, if it is hung over both lines at the same time, it dries quicker in tifastt_i^{\text{fast}} minutes, but also takes up space on the other line. To avoid smelly sheets, Harry the Beaver has to start drying all of them immediately after washing, i.e. all sheets have to be hung simultaneously.

Harry the Beaver wants to go to sleep as soon as possible on Sundays, therefore, he asks you to help him determine the minimal required drying time for each week jj, or inform him that it is impossible to finish drying the sheets that week.

输入格式

The first line contains an integer NN, the number of sheets, and an integer QQ, the number of weeks until the end of the tourist season. The next NN lines contain space-separated integers did_i, tifastt_i^{\text{fast}}, and tislowt_i^{\text{slow}}, which correspond to the width, the shorter drying time, and the longer drying time of the ii-th sheet, respectively. The final QQ lines the the input contain integers LjL_j, jj-th of which represents the length of the clothesline for week jj.

输出格式

Print QQ lines, with jj-th of them containing the minimal required drying time for week jj, or "-1" (without the quotes) if it is impossible to finish drying the sheets that week.

3 3
1 2 2
1 1 4
2 3 100
3
1
4
4
-1
3

提示

Input limits

  • 1N31041 \leq N \leq 3 \cdot 10^4
  • 1Q31051 \leq Q \leq 3 \cdot 10^5
  • 1di31051 \leq d_i \leq 3 \cdot 10^5 for all 1iN1 \leq i \leq N
  • $1 \leq t_i^{\text{fast}} \leq t_i^{\text{slow}} \leq 10^9$ for all 1iN1 \leq i \leq N
  • 1Lj31051 \leq L_j \leq 3 \cdot 10^5 for all 1jQ1 \leq j \leq Q