#P2722. Optimal Problem Selection

    ID: 15985 Type: Default 1000ms 256MiB

Optimal Problem Selection

Optimal Problem Selection

You are given a total competition time T and n categories of contest problems. For each category i (1 ≤ i ≤ n), three integers are provided:

  • mi: the maximum number of problems available in category i,
  • ti: the time required to solve each problem in category i, and
  • pi: the score obtained for solving a problem in category i.

Your task is to choose a nonnegative integer ki (0 ≤ ki ≤ mi) for each category such that the total solving time

[ \sum_{i=1}^{n} k_i \cdot t_i \le T ]

and the total score

[ \sum_{i=1}^{n} k_i \cdot p_i ]

is maximized. In case of multiple optimal solutions, any one is acceptable. Output the vector (k1, k2, \ldots, kn) in order.

inputFormat

The first line of the input contains two integers T and n, representing the total available time and the number of categories, respectively.

Then follow n lines, each containing three integers: mi, ti, and pi (for 1 ≤ i ≤ n) separated by spaces.

outputFormat

Output a single line with n integers. The i-th integer represents the number of problems chosen from category i in an optimal selection.

sample

10 2
5 2 3
3 3 4
5 0