Painting the Walls

You are given two 0-indexed integer arrays, cost and time, of size n representing the costs and the time taken to paint n different walls respectively. There are two painters available:

  • A paid painter that paints the i^th wall in time[i] units of time and takes cost[i] units of money.
  • A free painter that paints any wall in 1 unit of time at a cost of 0. But the free painter can only be used if the paid painter is already occupied.

Return the minimum amount of money required to paint the n walls.

Example 1
Inputcost = [1,2,3,2], time = [1,2,3,2]
Output3
The walls at index 0 and 1 are painted by the paid painter for a total cost of 3 while the free painter paints the remaining walls during that time.
Example 2
Inputcost = [2,3,4,2], time = [1,1,1,1]
Output4
The walls at index 0 and 3 are painted by the paid painter for a total cost of 4 while the free painter paints the remaining walls during that time.

Constraints

  • 1 <= cost.length <= 500
  • cost.length == time.length
  • 1 <= cost[i] <= 10^6
  • 1 <= time[i] <= 500

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate