Metropolis Development

시간 제한5초메모리 제한1024 MB

요약
구간 1부터 k까지 모든 지점이 덮이도록 구간 부분집합을 골랐을 때 각 지점에 더해지는 압력 합의 최댓값을 최소로 만든다.
난이도

보통10점 중 7점

유형
이분 탐색, 그리디, 정렬, 구간
정답자
아직 제출이 없습니다

문제

In the year 20yy20yy Moscow city completely ran out of space for the new construction works. The government is actively looking for the new income opportunities, and it finally announced that all railway tracks within the city boundaries are going to be replaced by the underground tunnels. Quite obviously, freed space will be used for development.

Reconstruction process begins with the section of Octyabrskaya Railway Tracks, which is kk meters long. Vacant space will attract a lot of tourists, but should balance its pressure onto the tunnel --- that means only the most important businesses get a chance to use the newly emerged area, like coffee stops and ice-cream vans.

Renovated track consists of kk equal segments, conveniently numbered from 11 to kk. There are nn companies willing to use the new territory, and ii-th of them would like to use all the segments numbered from l_il\_i to r_ir\_i. Every company provided a detailed construction plan including integer p_ip\_i --- the building's pressure. Every company's application can either be rejected, or accepted: there is no way to build only a part of any.

Since the major is quite greedy, he wants to make sure that each segment is used by at least one company. However, for safety reasons it was decided to minimize the maximal pressure on any segment. Please note that it's possible for one segment to be used by multiple companies, and in this case the total pressure is determined as a sum of individual pressure values of the buildings.

Please help the major to accept a set of applications so for every segment there is at least one accepted application which intend to use this segment, and the maximal pressure among the segments is as small as possible.

입력

The first line of the input contains two integers nn and kk (1≤n≤100,0001 \leq n \leq 100\\,000, 1≤ k≤1091 \leq\ k \leq 10^9) --- the number of applications and the number of individual segments.

The following nn lines describe the applications. Every application consists of three integers l_il\_i, r_ir\_i, p_ip\_i (1≤l_i≤r_i≤1091 \leq l\_i \leq r\_i \leq 10^9, 1≤p_i≤1091 \leq p\_i \leq 10^9), indicating the leftmost point, the rightmost point and the pressure, respectively.

출력

Output one number --- the lowest possible maximum pressure among all segments for a set of applications satisfying the requirements, or −1-1 if such set of applications doesn't exist.

힌트

In the first example the optimal strategy is to accept the first two applications. In this case the maximum pressure is attained on the third segment and equals 33.

In the second example there are no companies willing to use the third segment, and thus it's not possible to satisfy the requirements.

In the third example one of the optimal solutions is to accept all the applications. The maximum pressure is attained on the fourth segment and equals 88. Note that you don't need to minimize or maximize the total number of accepted applications.

In the fourth example the optimal solution is to accept the first and the fourth applications, leading to a valid configuration where the pressure of every segment is equal to 11.

예제4

  1. 예제 1

    입력
    3 4
    1 3 1
    3 4 2
    1 4 5
    
    예상 출력
    3
    
  2. 예제 2

    입력
    1 3
    1 2 1
    
    예상 출력
    -1
    
  3. 예제 3

    입력
    4 5
    1 4 3
    4 5 5
    1 1 3
    1 2 1
    
    예상 출력
    8
    
  4. 예제 4

    입력
    4 5
    1 4 1
    4 5 1
    3 4 1
    5 5 1
    
    예상 출력
    1