문제
Farmer John is expanding his farm! He has identified the perfect location in the Red-Black Forest, which consists of trees () on a number line, with the -th tree at position ().
Environmental protection laws restrict which trees Farmer John can cut down to make space for his farm. There are restrictions () specifying that there must always be at least trees () in the line segment , including the endpoints (). It is guaranteed that the Red-Black Forest initially satisfies these restrictions.
Farmer John wants to make his farm as big as possible. Please help him compute the maximum number of trees he can cut down while still satisfying all the restrictions!
입력
Each input consists of () independent test cases. It is guaranteed that the sums of all and of all within an input each do not exceed .
The first line of input contains . Each test case is then formatted as follows:
The first line contains integers and .The next line contains the integers .Each of the next lines contains three space-separated integers: , and .
출력
For each test case, output a single line with an integer denoting the maximum number of trees Farmer John can cut down.
예제 입력 1
3
7 1
8 4 10 1 2 6 7
2 9 3
7 2
8 4 10 1 2 6 7
2 9 3
1 10 1
7 2
8 4 10 1 2 6 7
2 9 3
1 10 4
예제 출력 1
4
4
3
점수
Input 2: Inputs 3-5: Inputs 6-7: for all .Inputs 8-11: No additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인