eolymp
bolt
Try our new interface for solving problems
Məsələlər

Russian Dolls

Russian Dolls

Maybe you know the famous russian souvenir Russian Dolls. It looks like a set of nested wooden dolls. A doll with a smaller size is placed inside a bigger one. Let's consider all dolls taken apart. Each doll has an outer volume \textbf{out}_\{i \}which is the volume it occupies in space and an inner volume \textbf{in_i} - the volume of the empty space inside the doll. You may assume that you can put one doll inside another if the outer volume of the first doll is strictly less than the inner volume of the second one. If two or more dolls are inside another one they can't lie one near the other, they must be nested. For each doll the cost of unit of empty space - \textbf{cost_i} is known. You must pay exactly \textbf{cost_i} for each unit of empty space which directly belongs to the \textbf{i}-th doll (but not to ones inside it). You may arrange the dolls the way you want as long as you are not contradicting the rules. The objective is to find an arrangement of nesting the dolls (not necessarily all of them) such that the overall cost you have to pay is minimized. \InputFile First line contains an integer N (\textbf{1} ≤ \textbf{N} ≤ \textbf{1000}) which is the number of dolls you have. The \textbf{i}-th of the next \textbf{N} lines contains three integers \textbf{out_i}, \textbf{in_i}, \textbf{cost_i} (\textbf{1} ≤ \textbf{in}_\{i \}< \textbf{out}_\{i \}≤ \textbf{1000}, \textbf{1} ≤ \textbf{cost}_\{i \}≤ \textbf{1000}), which are the outer volume, inner volume and the empty space cost of the \textbf{i}-th doll. \OutputFile Single integer \textbf{P} which is the minimum possible cost you should pay.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
3
5 4 1
4 2 2
3 2 1
Çıxış verilənləri #1
7
Mənbə 2013 South Eastern European Regional Programming Contest, Vinnica & Bucharest, October 12, Problem A