Segments Removal
시간 제한4초메모리 제한2048 MB
가중치와 벌점이 있는 선분들을 제거하는 순서를 정해 총 점수를 최대화합니다. 선분을 제거할 때 그 순간 그 선분만 덮는 정수 좌표의 수에 가중치를 곱한 만큼 점수를 얻습니다.
문제
Consider points on a coordinate axis. You are given a collection of segments that start and end in these points. Each segment has weight and penalty associated with it.
Initially, you have a score of . You can make moves. In each move, you select a segment from the given collection, remove it from the collection, and your score decreases by the penalty associated with the segment. In return, your score increases by the weight of the segment multiplied by the number of points with integer coordinates such that, at this moment of time, this segment is the only segment in the collection that covers these points. A segment is considered to cover its endpoints.
The total score is the sum of scores for the moves you make. Find the maximum total score you can achieve.
입력
The first line contains an integer (), the number of test cases. The test cases follow.
The first line of each test case contains two integers: the number of segments () and the maximum coordinate ().
Next lines contain the description of segments. Each line contains four integers: the start and end of the segment (), its weight () and penalty ().
The sum of over all test cases does not exceed . The sum of over all test cases does not exceed .
출력
For each test case, print a line containing one integer: the maximum possible score you can achieve.