Class Solution
java.lang.Object
g2701_2800.s2742_painting_the_walls.Solution
2742 - Painting the Walls.<p>Hard</p>
<p>You are given two <strong>0-indexed</strong> integer arrays, <code>cost</code> and <code>time</code>, of size <code>n</code> representing the costs and the time taken to paint <code>n</code> different walls respectively. There are two painters available:</p>
<ul>
<li>A** paid painter** that paints the <code>i<sup>th</sup></code> wall in <code>time[i]</code> units of time and takes <code>cost[i]</code> units of money.</li>
<li>A** free painter** that paints <strong>any</strong> wall in <code>1</code> unit of time at a cost of <code>0</code>. But the free painter can only be used if the paid painter is already <strong>occupied</strong>.</li>
</ul>
<p>Return <em>the minimum amount of money required to paint the</em> <code>n</code> <em>walls.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> cost = [1,2,3,2], time = [1,2,3,2]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> The walls at index 0 and 1 will be painted by the paid painter, and it will take 3 units of time; meanwhile, the free painter will paint the walls at index 2 and 3, free of cost in 2 units of time. Thus, the total cost is 1 + 2 = 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> cost = [2,3,4,2], time = [1,1,1,1]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> The walls at index 0 and 3 will be painted by the paid painter, and it will take 2 units of time; meanwhile, the free painter will paint the walls at index 1 and 2, free of cost in 2 units of time. Thus, the total cost is 2 + 2 = 4.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= cost.length <= 500</code></li>
<li><code>cost.length == time.length</code></li>
<li><code>1 <= cost[i] <= 10<sup>6</sup></code></li>
<li><code>1 <= time[i] <= 500</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
paintWalls
public int paintWalls(int[] cost, int[] time)
-