Under construction

Still being built. Things may change

Perfume

Time limit8sMemory limit1024 MB

Summary
Place K perfume bottles on a line to maximize the total weight of intervals that contain at least one bottle position.
Level

Medium7 of 10

Topics
Intervals, Greedy, Shortest path
Solved
No attempts yet

Problem

The year is almost over. Christmas carols and small twinkling lights line the streets. Hope and relief show on people's faces, but some faces carry regret and anxiety as a faint shadow.

Jaemin is happy to see 2021 go, and tonight he has decided to give people happiness.

Tonight, NN people will spend their time walking along a road on an infinitely long vertical number line.

The ii-th person starts walking in the positive direction from position lil_i and leaves the road at position rir_i.

Jaemin has KK bottles of perfume. The perfume has a magical power that makes whoever smells it happy. The amount differs per person: the ii-th of the NN people gains happiness wiw_i when they smell it.

Jaemin wants to place the perfume bottles on the road so that the total happiness is maximized. However, because of the strong wind, a person can smell a bottle only if they pass exactly the position where it is placed. A person can smell a bottle at an endpoint of their path, and even if they smell several bottles, they gain happiness only once.

Help Jaemin give happiness to people and close out the year.

Input

The first line contains NN and KK, separated by a space. (1≤K≤N≤200,0001 \le K \le N \le 200,000)

Each of the next NN lines contains lil_i, rir_i, and wiw_i, separated by spaces. (−109≤li≤ri≤109-10^9 \le l_i \le r_i \le 10^9, 1≤wi≤10,0001 \le w_i \le 10,000)

Output

Print the maximum total happiness the people can gain when the KK bottles are placed optimally, on one line.

Examples1

  1. Example 1

    Input
    7 2
    1 2 10
    2 5 8
    3 7 3
    4 6 1
    7 8 5
    8 9 9
    9 10 2
    
    Expected output
    32