Problem Description as the saying goes, it's hard for a hero to lose a penny. After years of high school, elder brother has already understood this truth. Therefore, it has become a habit to store personal funds for one year since the New Year, however, since college, he has been embarrassed to ask for money from adults. He can only put his only hope on his own. However, due to the special nature of the time period and the factors of his own ability, he can only find some fragmented jobs. He wants to know how to arrange his vacation to get the most salary.
It is known that jige has a total of m days of vacation, and the number of each day ranges from 1 to m, a total of n jobs can be done, each job knows the start time s, end Time e and corresponding salary c. the start time and end time of each job are in the unit of day (number of days). the end time of each job must be the end time to get the total salary c, and there cannot be jobs with overlapping time. For example, a job that starts from 1st days and ends from 2nd days cannot start with 2nd days, and a job that ends from 4th days is selected together, because 2nd days Ji Ge can only work in one place.
Now, gigo wants to know how to get the maximum salary within m days of the holiday (day m + 1 gigo must return to school, m days later ).
The first line of Input is the number of groups of data T; the first line of each group of data is two positive integers: the holiday time m and the number of work that can be done n; the next n rows have three positive integers describing the start time s, end time e, and total salary c of the corresponding n jobs.
[Technical Specification]
1 <= T <= 1000
9 0 S <= 100, e <= 100, s <= e
C <= 10000
Output: for each group of data, Output the highest salary that jige can obtain.
Sample Input
110 51 5 1003 10 105 10 1001 4 26 12 266
Sample Output
102
# Include
# Include
Int e [110] [110], dp [110], t, m, n; // e [I] [j] records the benefits from day I to day j, dp [I] indicates the maximum benefit int Max (int a, int B) {return a> B? A: B;} int main () {scanf ("% d", & t); while (t --) {scanf ("% d", & m, & n); memset (e, 0, sizeof (e); memset (dp, 0, sizeof (dp); for (int I = 1; I <= n; I ++) {int a, B, c; scanf ("% d", & a, & B, & c ); if (B> m | c <= e [a] [B]) continue; // skip e [a] [B] = c;} for (int I = 1; I <= m; I ++) for (int j = 0; j