#P6093. [JSOI2015] 套娃

[JSOI2015] 套娃

Description

JYY has a total of NN disassembled nesting dolls, numbered from 11 to NN. Doll ii has an outer diameter OutiOut_i and an inner diameter IniIn_i (Ini<OutiIn_i<Out_i).

For dolls ii and jj, if Outi<InjOut_i<In_j, then doll ii can be put inside doll jj.

Note that inside a single doll, it is not allowed to place multiple dolls side by side.

That is, if we put ii inside jj, and there is another doll kk that also satisfies Outk<InjOut_k<In_j, then we are not allowed to put kk inside jj at this time (because jj already contains ii). However, if kk also satisfies Outk<IniOut_k<In_i, then we are allowed to first put kk inside ii, and then put kk and ii together as a whole into jj.

JYY believes that a good set of nesting dolls should have as little empty space inside as possible. If doll jj contains doll ii, then we define the empty space produced inside doll jj as InjOutiIn_j-Out_i. If doll jj contains nothing, then the empty space of doll jj is InjIn_j.

JYY also hopes that the better-looking dolls should be filled as much as possible; for the less good-looking ones, he cares relatively less. Therefore, JYY assigns each doll ii a beauty value BiB_i. If this doll still has KK empty space inside, then JYY will have a dissatisfaction of K×BiK\times B_i for this doll.

The dissatisfaction of a nesting plan is the sum of the dissatisfaction produced by each doll. JYY wants to find a nesting plan with the minimum total dissatisfaction.

Input Format

The first line contains a positive integer NN. The next NN lines each contain three positive integers Outi,Ini,BiOut_i,In_i,B_i, representing the outer diameter, inner diameter, and beauty value of doll ii.

Output Format

Output one integer in a single line, representing the minimum possible dissatisfaction.

3
5 4 1
4 2 2
3 2 1
7

Hint

For 100%100\% of the testdata, N2×105N\leq 2\times 10^5, 1Ini<Outi1041\leq In_i<Out_i\leq 10^4, 1Bi1091\leq B_i\leq 10^9.

Translated by ChatGPT 5