#P3592. [POI 2015 R3] 洗车 Car washes

[POI 2015 R3] 洗车 Car washes

Description

There are nn car wash shops arranged in a row from left to right. Each shop has a positive integer price pip_i. There are mm customers. The ii-th customer will drive past shops from the aia_i-th to the bib_i-th, inclusive, and will choose the cheapest shop among these to buy one wash. However, if this cheapest price is greater than cic_i, then this person does not buy a wash. Assign a price to each shop so that the total amount spent by all customers is maximized.

Input Format

The first line contains two positive integers n,mn, m (1n501 \le n \le 50, 1m40001 \le m \le 4000).
The next mm lines each contain three positive integers ai,bi,cia_i, b_i, c_i (1aibin1 \le a_i \le b_i \le n, 1ci5×1051 \le c_i \le 5\times 10^5).

Output Format

On the first line, output a single positive integer — the maximum total spending.
On the second line, output nn positive integers, representing the prices pip_i of each shop from left to right, with 1pi5×1051 \le p_i \le 5\times 10^5. If there are multiple optimal solutions, output any of them.

7 5
1 4 7
3 7 13
5 6 20
6 7 1
1 2 5
43
5 5 13 13 20 20 13

Hint

Original title: Myjnie.

Translated by ChatGPT 5