#P6249. 神帖

神帖

Description

Legendary posts are distributed on some pages in the forum, and each page has at most one legendary post. Suppose the page he is currently browsing is page 00. One page to the left is page 1-1, and one page to the right is page 11, and so on. The ii-th legendary post is on page xix_i, and it has a specific ban time tit_i and happiness value viv_i. If he browses it after time tit_i, he cannot get its happiness value. It takes 11 unit of time for zrl to flip one page left or right, and browsing a legendary post takes no time. Ask: what is the maximum total happiness value zrl can obtain.

Note: If he browses the ii-th legendary post at exactly tit_i units of time, he can still get viv_i happiness value.

Additional note: the happiness value of each legendary post can be obtained at most once.

Input Format

The first line contains an integer nn, indicating the number of legendary posts.

The next nn lines each contain three integers, representing xix_i, viv_i, and tit_i of the ii-th legendary post.

Output Format

One integer, the maximum happiness value zrl can obtain.

5
-5 1 5
-3 1 5
-1 1 5
1 1 5
3 2 5

4
5
-5 2 5
-3 1 5
-1 1 5
1 0 5
3 4 5

5
5
1 1 1
2 1 2
3 1 3
4 1 5
-5 5 5

5

Hint

Sample Explanation

Sample 1: $0 \rightarrow -1 \rightarrow 0 \rightarrow 1 \rightarrow 2 \rightarrow 3$
Sample 2: $0 \rightarrow -1 \rightarrow 0 \rightarrow 1 \rightarrow 2 \rightarrow 3$
Sample 3: $0 \rightarrow -1 \rightarrow -2 \rightarrow -3 \rightarrow -4 \rightarrow -5$


Constraints

Test Point Special Property
121-2 xi0x_i \ge 0
343-4 0ti200 \le t_i \le 20
565-6 n20n \le 20
77 10xi10-10 \le x_i \le 10
898-9 ti=t_i =|xix_i|
101310-13 all tit_i are equal
141714-17 n60n \le 60
172217-22 none

For 100%100\% of the testdata: n200n \le 200, 500xi500-500 \le x_i \le 500, 0vi1090 \le v_i \le 10^9, 0ti5000 \le t_i \le 500.

Hint: Two new groups of hack testdata have been added, so greedy/simulation can no longer pass.

Translated by ChatGPT 5