QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#14642. Meble

الإحصائيات

Bajtazar intends to furnish his new apartment. For this purpose, he went to one of the nearby BITKEA stores and bought furniture of $n$ types, specifically $c_i$ items of furniture of type $i$.

Assembling the first furniture item of type $i$ (including studying the instructions in the Bajto-Swedish language) will take him $a_i$ minutes. While assembling further items, Bajtazar will gain experience — assembling the second and each subsequent furniture item of type $i$ will take him $d_i$ minutes less than assembling the previous item of that type.

Bajtazar decided that he will assemble some number of furniture items today. For each value $m_i$, he would like to know the minimum time in which he can assemble some $m_i$ of the purchased furniture items.

Input

The first line of the input contains two integers $n$ and $k$ ($1 \le n, k \le 500$), denoting respectively the number of furniture types and the number of queried values $m_i$. In the $i$-th of the next $n$ lines there are three integers $a_i, d_i, c_i$ ($1 \le a_i, d_i, c_i \le 10^9$, $a_i > (c_i - 1) \cdot d_i$), describing the $i$-th type of purchased furniture. In the $i$-th of the next $k$ lines there is an integer $m_i$ ($1 \le m_i \le 20,000$).

In tests worth 10% of the points, the condition $1 \le n \le 50$ holds.

In tests worth 50% of the points, the condition $1 \le m_i \le 3000$ holds.

In tests worth 70% of the points, at least one of the above conditions holds.

Output

Print $k$ lines; in the $i$-th of them, output the minimum number of minutes needed to assemble $m_i$ furniture items. You may assume that assembling some $m_i$ furniture items will always be possible.

Example

For the input:

3 6
20 3 6
25 20 2
19 1 19
1
2
3
4
5
6

the correct output is:

19
30
49
62
70
75

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.