#P1250. 种树

种树

Description

The roadside area is divided into blocks and numbered 1,2,,n1, 2, \ldots,n. Each block has unit size and can contain at most one tree.

Each resident wants to plant some trees in front of their house and specifies three numbers bb, ee, tt. These numbers mean that the resident wants at least tt trees in the area between bb and ee (inclusive of bb and ee).

Different residents’ desired intervals may overlap. Your task is to find the minimum number of trees that can satisfy all requirements.

Input Format

The first line contains an integer, the number of areas nn.

The second line contains an integer, the number of houses hh.

Lines 33 to (h+2)(h + 2) each contain three integers. On line (i+2)(i + 2), the integers are bi,ei,tib_i, e_i, t_i, meaning the ii-th resident wants at least tit_i trees between bib_i and eie_i.

Output Format

Output a single integer, the minimum number of trees.

9
4
1 4 2
4 6 2
8 9 2
3 5 2
5

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1n3×1041 \leq n \leq 3 \times 10^41h5×1031 \leq h \leq 5 \times 10^3
  • 1biein1 \leq b_i \leq e_i \leq n1tieibi+11 \leq t_i \leq e_i - b_i + 1

Translated by ChatGPT 5