Popcorn

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

요약
고른 조리 시간들 중 하나가 구간 [A_i, B_i)에 들어가는 팝콘 종류의 양의 합이 최대가 되도록 M개 이하의 시간을 고르는 문제이다.
난이도

보통10점 중 6점

유형
정렬, 그리디, 구간, 동적 계획법
정답자
아직 제출이 없습니다

문제

We all know that popcorn is a culinary delicacy. While you were preparing for this year's selection camp (and the after parties), you ordered NN types of microwave popcorn. For each different type you know 33 values:

  • A_iA\_i ​= the time (in seconds) when the popcorn of type ii pops
  • B_iB\_i ​= the time (in seconds) then the popcorn of type ii gets burned
  • C_iC\_i ​= the quantity of popcorn of type ii

You also have MM disposable popcorn bags of large capacity (practically, infinite) and a microwave oven. As, of course, no one likes burned or unpopped popcorn, you wish to partition it in the MM bags and then put those in the oven, setting a certain cooking time prep_iprep\_i, such that in the end you'll have as much edible popcorn as possible.

Formally, the popcorn of type ii used in bag jj, which was cooked in the oven prep_jprep\_j seconds, is edible if and only if A_i≤prep_j\<B_iA\_i≤prep\_j\<B\_i.

Given NN types of popcorn and the number of available bags, you have to find a convenient partition and the cooking times for each bag, such that in the end you'll have as much edible popcorn as possible. Output the quantity of edible popcorn. Too simple!

입력

The first line contains two integers NN and MM.

Each of the next NN lines contains 33 integers A_iA\_i, B_iB\_i, C_iC\_i, corresponding to each popcorn type.

출력

Output a single integer representing the maximum quantity of edible popcorn you can get.

제한

  • 1≤M≤N≤200,0001≤M≤N≤200\\, 000
  • 1≤A_i≤B_i≤200,0001≤A\_i≤B\_i≤200\\, 000
  • The total quantity of popcorn doesn't exceed 10910^9
  • Some bags can be left empty!
  • Let X=max⁡N,B\[1],B\[2],…,B\[N]X=\max\\{N,B\[1],B\[2],\dots ,B\[N]\\}

예제2

  1. 예제 1

    입력
    5 2
    2 4 3
    1 5 6
    4 8 10
    7 8 2
    10 11 2
    
    예상 출력
    21
    
  2. 예제 2

    입력
    3 3
    1 2 2
    2 3 3
    1 3 5
    
    예상 출력
    10