#FT0000092. Nhà máy vòng tháp Hà Nội (Hanoi Factory)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nhà máy vòng tháp Hà Nội (Hanoi Factory)
Hanoi Factory
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A factory has manufactured rings in stock. Ring has inner radius , outer radius , and height . Its inner radius is strictly smaller than its outer radius.
The factory wishes to build the tallest possible tower using some of these rings, each at most once. If ring is placed immediately above ring , both conditions must hold:
- The upper ring's outer radius cannot exceed that of the lower ring: .
- The upper ring must not fall into the lower ring's hole: .
The tower's height is the sum of the chosen rings' heights. A tower of one ring is allowed. Find the maximum achievable height.
Input
The first line contains the integer . Each of the next lines contains three integers , , and for ring .
Output
Print one integer: the maximum total height of a valid tower.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Example 1
Input
3
1 5 1
2 6 2
3 7 3
Output
6
Explanation
The rings have heights . Place ring (outer radius ) at the bottom, ring () in the middle, and ring () on top. The adjacent pairs satisfy , , , and . The total height is . Since this uses every ring, no tower can be taller.
Example 2
Input
4
1 2 1
1 3 3
4 6 2
5 7 1
Output
4
Explanation
Rings and can form a tower: and . Their height is . Rings and also form a valid tower, but its height is only . The two groups cannot be stacked together while maintaining the radius rules. Therefore, the answer is .