Group Division
Time limit1.5sMemory limit1024 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
Divide people into groups. Each person belongs to exactly one group, and each group has exactly one leader. Person has three integers , , and that describe their leadership ability. Person can lead a group of people if . If , person must be alone in their group to lead. The strength of such a group is the integer . Divide the people into groups so that the sum of the group strengths is maximized.
Input
The first line contains an integer (), the number of people. Each of the next lines contains three integers , , and (, ).
Output
Print one integer: the maximum possible sum of group strengths.
Hints
In the first sample, the maximum strength is achieved, for example, by splitting the people into three groups: one with persons 1 and 4 (leader 1), one with persons 3 and 5 (leader 3), and one with person 2. This gives strength. This test case could be part of test group 3.
In the second sample, the maximum strength is achieved, for example, by splitting the people into two groups: one with persons 1, 2, and 3 (leader 3), and one with persons 4 and 5 (leader 4). This gives strength. This test case could be part of test group 4.