#P6093. [JSOI2015] 套娃
[JSOI2015] 套娃
Background
JYY has just returned from a trip to Russia and bought a lot of beautiful nesting dolls as souvenirs. Because JYY was too excited, he opened all of the nesting dolls. Since many of the dolls look very similar, JYY now does not know how to put them back (he really cannot figure out which doll should be put into which).
Problem Description
JYY has a total of disassembled nesting dolls, numbered from to . Doll has an outer diameter and an inner diameter ().
For dolls and , if , then doll can be put inside doll .
Note that inside a single doll, it is not allowed to place multiple dolls side by side.
That is, if we put inside , and there is another doll that also satisfies , then we are not allowed to put inside at this time (because already contains ). However, if also satisfies , then we are allowed to first put inside , and then put and together as a whole into .
JYY believes that a good set of nesting dolls should have as little empty space inside as possible. If doll contains doll , then we define the empty space produced inside doll as . If doll contains nothing, then the empty space of doll is .
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 a beauty value . If this doll still has empty space inside, then JYY will have a dissatisfaction of 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 . The next lines each contain three positive integers , representing the outer diameter, inner diameter, and beauty value of doll .
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 of the testdata, , , .
Translated by ChatGPT 5