#P1986. Minimum Microphones
Minimum Microphones
Minimum Microphones
Brett's class has a performance where each of the students stands in a row holding a microphone while singing a song. The class is divided into contiguous groups, where the -th group consists of students with indices from to (inclusive). Note that a student may belong to multiple groups or none at all. To ensure a good performance, each group must have at least students holding microphones. Your task is to determine the minimum number of microphones required.
inputFormat
The first line contains two integers and . Each of the following lines contains three integers , , and , representing the starting and ending indices of the -th group and the minimum number of microphones required for that group, respectively.
outputFormat
Output a single integer, the minimum number of microphones needed.
sample
5 2
1 3 2
4 5 1
3