Imagine you're planning a road trip on a straight highway of length l km. Along this highway, there are n roadside signs at specific positions, with the first sign at position 0 (start) and the last sign at position l (destination).
Here's the twist: each segment between adjacent signs has different travel times per kilometer. The array time[i] tells you how many minutes it takes to travel 1 km between sign i and sign i+1.
You have a special power: you can perform exactly k merge operations. In each merge, you can:
- Choose two adjacent signs at positions
iandi+1(wherei > 0andi+1 < n-1) - Combine their travel times:
time[i+1] = time[i] + time[i+1] - Remove the sign at position
i
Goal: After performing exactly k merges, find the minimum total travel time to go from position 0 to position l.
Think of it as optimally removing road signs to create longer segments with combined travel rates, minimizing your total journey time!
Input & Output
Constraints
- 2 โค n โค 1000
- 1 โค k โค n - 2
- 1 โค l โค 105
- position[0] = 0 and position[n-1] = l
- 1 โค time[i] โค 100
- position array is strictly increasing