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

#BS0000469. Các dự án (Projects)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Các dự án (Projects)

Projects

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn projects, each with start sis_i, end eie_i and reward viv_i for completing it. Select any subset of the projects 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 nn. 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≤n≤301\le n\le 30; 1≤si≤ei≤1091\le s_i\le e_i\le10^9; 1≤vi≤10000000001\le v_i\le 1000000000 (1≤i≤n1\le i\le n).
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤si≤ei≤1091\le s_i\le e_i\le10^9; 1≤vi≤10000000001\le v_i\le 1000000000 (1≤i≤n1\le i\le n).
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤si≤ei≤1091\le s_i\le e_i\le10^9; 1≤vi≤10000000001\le v_i\le 1000000000 (1≤i≤n1\le i\le n).

Examples

Example 1

Input

4
2 4 4
3 6 6
6 8 2
5 7 3

Output

7

Explanation

Choose projects 1 and 4 for reward 7. Project 2 overlaps all others; project 3 can only join project 1 for 6.