A hiker is planning a multi-day trek through the mountains. There are n tralls, each…
- User
A hiker is planning a multi-day trek through the mountains. There are n tralls, each with a certain length, given as a list, trails, that need to be hiked in the order in the list. The hiker wants to achieve a new world record by completing the trek in record number of days. Each day, the hiker will cover at least one trail and must minimize the sum of the lengths of the longest trail hiked each day. Find this minimum sum.
Example
There are n = 6 trails with lengths trails = [10, 5, 9, 3, 8, 15), and record = 2.
One optimal solution is for the hiker to cover the first trail on the first day, and the remaining tralls on the second day. On the first day, the longest trail is 10, and on the second day, It is max(5, 9, 3, 8, 15) = 15. The sum of the lengths of the longest trails is 10 + 1525. Return 25.
Function Description
Complete the function efficient Trek in the editor below.
efficient Trek has the following parameters: Int trails[]: an array of integers denoting the order and length of the tralls.
Int record: the number of days to cover all the trails.
Returns
int: the minimum sum of the longest tralls on each day
Constraints
1 ≤ n ≤ 300
1 ≤ record ≤ n ≤ 300
. 1 ≤ trails[i] ≤ 105
- Assistant