Class Solution
-
- All Implemented Interfaces:
public final class Solution3538 - Merge Operations for Minimum Travel Time.
Hard
You are given a straight road of length
lkm, an integern, an integerk** , ** and two integer arrays,positionandtime, each of lengthn.The array
positionlists the positions (in km) of signs in strictly increasing order (withposition[0] = 0andposition[n - 1] = l).Each
time[i]represents the time (in minutes) required to travel 1 km betweenposition[i]andposition[i + 1].You must perform exactly
kmerge operations. In one merge, you can choose any two adjacent signs at indicesiandi + 1(withi > 0andi + 1 < n) and:Update the sign at index
i + 1so that its time becomestime[i] + time[i + 1].Remove the sign at index
i.
Return the minimum total travel time (in minutes) to travel from 0 to
lafter exactlykmerges.Example 1:
Input: l = 10, n = 4, k = 1, position = 0,3,8,10, time = 5,8,3,6
Output: 62
Explanation:
Merge the signs at indices 1 and 2. Remove the sign at index 1, and change the time at index 2 to
8 + 3 = 11.After the merge:
Total Travel Time:
40 + 22 = 62, which is the minimum possible time after exactly 1 merge.
Example 2:
Input: l = 5, n = 5, k = 1, position = 0,1,2,3,5, time = 8,3,9,3,3
Output: 34
Explanation:
Merge the signs at indices 1 and 2. Remove the sign at index 1, and change the time at index 2 to
3 + 9 = 12.After the merge:
Total Travel Time:
16 + 12 + 6 = 34** , ** which is the minimum possible time after exactly 1 merge.
Constraints:
<code>1 <= l <= 10<sup>5</sup></code>
2 <= n <= min(l + 1, 50)0 <= k <= min(n - 2, 10)position.length == nposition[0] = 0andposition[n - 1] = lpositionis sorted in strictly increasing order.time.length == n1 <= time[i] <= 1001 <= sum(time) <= 100
-
-
Constructor Summary
Constructors Constructor Description Solution()
-