PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000463. Tham dự sự kiện có giới hạn (Maximum Number of Events That Can Be Attended II)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tham dự sự kiện có giới hạn (Maximum Number of Events That Can Be Attended II)

Maximum Number of Events That Can Be Attended II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn events, each with start sis_i, end eie_i and reward viv_i for completing it. Select at most kk events without overlap. Both endpoints are inclusive, so the next start must be strictly greater than the previous end. Maximize the total reward.

Input

The first line contains n,kn,k. The next nn lines each contain three integers si,ei,vis_i,e_i,v_i.

Output

Print the largest total reward.

Subtasks

  • Subtask 1 (20 points): 1≤k≤n1\le k\le n; 1≤nk≤1001\le nk\le 100; 1≤si≤ei≤1091\le s_i\le e_i\le10^9; 1≤vi≤10000001\le v_i\le 1000000 (1≤i≤n1\le i\le n).
  • Subtask 2 (30 points): 1≤k≤n1\le k\le n; 1≤nk≤100001\le nk\le 10000; 1≤si≤ei≤1091\le s_i\le e_i\le10^9; 1≤vi≤10000001\le v_i\le 1000000 (1≤i≤n1\le i\le n).
  • Subtask 3 (50 points): 1≤k≤n1\le k\le n; 1≤nk≤10000001\le nk\le 1000000; 1≤si≤ei≤1091\le s_i\le e_i\le10^9; 1≤vi≤10000001\le v_i\le 1000000 (1≤i≤n1\le i\le n).

Examples

Example 1

Input

3 2
1 2 4
3 4 3
2 3 1

Output

7

Explanation

Events 1 and 2 yield 7.

Example 2

Input

3 2
1 2 4
3 4 3
2 3 10

Output

10

Explanation

Event 3 yields 10 and overlaps the other two.

Example 3

Input

4 3
1 1 1
2 2 2
3 3 3
4 4 4

Output

9

Explanation

Choose the three highest rewards: 2,3,4.