Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 65536/65536 K (Java/Others)

Luras is fond of playing games. Once she gets free, she might try playing games such as dato and cf.

However, if you have read the past problems, you will know that luras is very busy even if she skips many classes.

As a result, she wants to arrange her time for playing more rounds of games during her free time.

It is known that luras has m types of games which she is willing to play, and for each game type, there is a time segment,

luras will only try playing one game type during its limited time segment (and ofc in the class-skipping time).

Besides, you are told of the needed time for each round of every game type.

Be attention, once luras started a game, she needs to finish it without any break during the limited time.

Now please help luras arrange her time in order to play more rounds of games.

However, if you have read the past problems, you will know that luras is very busy even if she skips many classes.

As a result, she wants to arrange her time for playing more rounds of games during her free time.

It is known that luras has m types of games which she is willing to play, and for each game type, there is a time segment,

luras will only try playing one game type during its limited time segment (and ofc in the class-skipping time).

Besides, you are told of the needed time for each round of every game type.

Be attention, once luras started a game, she needs to finish it without any break during the limited time.

Now please help luras arrange her time in order to play more rounds of games.

The first line is an integer T which indicates the case number.

and as for each case,

the first line are two integer n and m which indicate the number of time segment of skipping the class and the game types luras wants to try.

then there are n lines, for the i-th line, there are 2 integers L[i] and R[i], which mean that luras could skip the class for games at the R[i] - L[i] + 1 time point { L[i], L[i] + 1, ..., R[i] - 1, R[i] }.

then there are m lines, for the i-th line, there are 3 integers l[i], r[i] and d[i], which mean that only during the r[i] - l[i] + 1 time point { l[i], l[i] + 1, ..., r[i] - 1, r[i] }, could luras play the i-th type game.

once luras spends a d[i] continuous time segment during [ l[i], r[i] ], she could finish 1 round of the i-th game.

At last please note luras could only play at most 1 round game at a time point, she is a cut noob : ) .

It is guaranteed that——

1 <= T <= 1000

1 <= L[1] <= R[1] < L[2] <= R[2] < ... < L[n] <= R[n] <= 10^9

1 <= l[] <= r[] <= 10^9

1 <= d[] <= 10^9

for 99% cases，1 <= n, m <= 100

for 100% cases，1 <= n, m <= 10000

and as for each case,

the first line are two integer n and m which indicate the number of time segment of skipping the class and the game types luras wants to try.

then there are n lines, for the i-th line, there are 2 integers L[i] and R[i], which mean that luras could skip the class for games at the R[i] - L[i] + 1 time point { L[i], L[i] + 1, ..., R[i] - 1, R[i] }.

then there are m lines, for the i-th line, there are 3 integers l[i], r[i] and d[i], which mean that only during the r[i] - l[i] + 1 time point { l[i], l[i] + 1, ..., r[i] - 1, r[i] }, could luras play the i-th type game.

once luras spends a d[i] continuous time segment during [ l[i], r[i] ], she could finish 1 round of the i-th game.

At last please note luras could only play at most 1 round game at a time point, she is a cut noob : ) .

It is guaranteed that——

1 <= T <= 1000

1 <= L[1] <= R[1] < L[2] <= R[2] < ... < L[n] <= R[n] <= 10^9

1 <= l[] <= r[] <= 10^9

1 <= d[] <= 10^9

for 99% cases，1 <= n, m <= 100

for 100% cases，1 <= n, m <= 10000

提交代码