#K41912. Maximum Non-Overlapping Task Value
Maximum Non-Overlapping Task Value
Maximum Non-Overlapping Task Value
You are given a set of tasks where each task is defined by its start time, end time, and value. Your goal is to select a subset of non-overlapping tasks that maximizes the total value. Two tasks are said to be non-overlapping if the start time of one is not less than the end time of another. Formally, given tasks ( (s_i, e_i, v_i) ) for ( i = 1, 2, \dots, n ), find a subset ( S ) such that for any two tasks ( (s_i, e_i, v_i) ) and ( (s_j, e_j, v_j) ) in ( S ) with ( i \neq j ), either ( e_i \le s_j ) or ( e_j \le s_i ), and the sum ( \sum_{i \in S} v_i ) is maximized.
inputFormat
The first line contains an integer ( n ) representing the number of tasks. Each of the next ( n ) lines contains three integers ( s ), ( e ), and ( v ) which represent the start time, the end time, and the value of a task respectively.
outputFormat
Output a single integer: the maximum sum of values obtainable by selecting non-overlapping tasks.## sample
1
1 2 10
10