Segments Removal

시간 제한4초메모리 제한2048 MB

요약
가중치와 벌점이 있는 선분들을 제거하는 순서를 정해 총 점수를 최대화합니다. 선분을 제거할 때 그 순간 그 선분만 덮는 정수 좌표의 수에 가중치를 곱한 만큼 점수를 얻습니다.
난이도

어려움10점 중 8점

유형
그리디, 세그먼트 트리, 정렬
정답자
아직 제출이 없습니다

문제

Consider points 1,2,…,x1, 2, \ldots, x 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 00. 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 tt (1≤t≤2⋅1051 \le t \le 2 \cdot 10^5), the number of test cases. The test cases follow.

The first line of each test case contains two integers: the number of segments nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) and the maximum coordinate xx (1≤x≤5⋅1051 \le x \le 5 \cdot 10^5).

Next nn lines contain the description of segments. Each line contains four integers: the start ℓ_i\ell\_i and end r_ir\_i of the segment (1≤ℓ_i≤r_i≤x1 \le \ell\_i \le r\_i \le x), its weight w_iw\_i (1≤w_i≤1091 \le w\_i \le 10^9) and penalty p_ip\_i (1≤p_i≤1091 \le p\_i \le 10^9).

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5. The sum of xx over all test cases does not exceed 5⋅1055 \cdot 10^5.

출력

For each test case, print a line containing one integer: the maximum possible score you can achieve.

예제1

  1. 예제 1

    입력
    2
    3 8
    3 7 3 2
    5 8 2 1
    1 3 2 2
    2 5
    1 3 2 7
    3 5 3 4
    
    예상 출력
    16
    2