luogu#P10934. 西瓜种植

西瓜种植

Background

Benben: Little watermelons, little watermelons~

Passer-by A: No way. These watermelons are clearly big...

Benben: Then... big watermelons, big watermelons~

Passer-by A: You changed your words so fast...

Benben: Watermelons, watermelons~ Cute watermelons~

Problem Description

Benben planted a watermelon field, but the planting area of this field is a straight line...

After some research, Benben came up with mm conclusions. These mm conclusions can maximize the number of watermelons he harvests.

Benben's conclusions are as follows:

From position bb to position ee in the field, at least tt watermelons must be planted, and then the harvest in this range can be maximized.

Benben does not want to work that hard, so he wants to plant as few watermelons as possible, while satisfying every conclusion he obtained.

Input Format

The first line contains two numbers nn and mm (0<n50000<n \le 5000, 0m30000 \le m\le 3000), meaning Benben's watermelon field has length nn, and Benben has obtained mm conclusions.

The next mm lines describe Benben's mm conclusions. Each line contains three numbers bb, ee, tt (1ben1 \le b\le e\le n, 0teb+10 \le t\le e-b+1).

Output Format

Output the minimum number of watermelons Benben needs to plant.

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

Hint

Basically, Benben's watermelon field is a spectacular line...

Translated by ChatGPT 5