Description
Solutions
Minimize Total Input Cost (for LTMS)

Campaigns should be executed in the order they appear. Each week must contain at least one campaign. Weekly input cost is equal to the maximum cost of any campaign in that week. The goal is to minimize the total input cost, which is the sum of weekly input costs.

Function Description

Complete the function minimizeTotalInputCost in the editor.

minimizeTotalInputCost has the following parameters:

  1. 1. int[] campaignCosts: an array of integers representing the costs of campaigns
  2. 2. int numberOfWeeks: the number of weeks

Returns

int: the minimized total input cost

Example 1:

Input:  campaignCosts = [1000, 500, 2000, 8000, 1500], numberOfWeeks = 3
Output: 9500
Explanation:
The input might not be right...But it looks correct somehow...

Optimal Allocation:

  1. Week 1: {1000} → Max Cost = 1000
  2. Week 2: {500} → Max Cost = 500
  3. Week 3: {2000, 8000, 1500} → Max Cost = 8000

Output:

  • Weekly Input Costs: {1000, 500, 8000}
  • Total Input Cost (TIC): 1000 + 500 + 8000 = 9500

Explanation:

  • Minimized Weekly Input: The maximum cost in any week is minimized.
  • Optimal Total Input Cost: The sum of all weekly maximum costs (9500) is the smallest possible.

Constraints:
    :)
Thumbnail 0
Testcase

Result
Case 1

input:

output: