Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2742 - Painting the Walls\.

    Hard

    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 <code>i<sup>th</sup></code> 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:

    Input: cost = 1,2,3,2, time = 1,2,3,2

    Output: 3

    Explanation: 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.

    Example 2:

    Input: cost = 2,3,4,2, time = 1,1,1,1

    Output: 4

    Explanation: 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.

    Constraints:

    • 1 &lt;= cost.length &lt;= 500

    • cost.length == time.length

    • <code>1 <= costi<= 10<sup>6</sup></code>

    • 1 &lt;= time[i] &lt;= 500

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer paintWalls(IntArray cost, IntArray time)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait