2742. Painting the Walls Hard

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [2742] Painting the Walls
3 *
4 * 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:
5 * 
6 * 	A paid painter that paints the i^th wall in time[i] units of time and takes cost[i] units of money.
7 * 	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.
8 * 
9 * Return the minimum amount of money required to paint the n walls.
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input: cost = [1,2,3,2], time = [1,2,3,2]
14 * Output: 3
15 * 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.
16 * 
17 * <strong class="example">Example 2:
18 * 
19 * Input: cost = [2,3,4,2], time = [1,1,1,1]
20 * Output: 4
21 * 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.
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	1 <= cost.length <= 500
27 * 	cost.length == time.length
28 * 	1 <= cost[i] <= 10^6
29 * 	1 <= time[i] <= 500
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/painting-the-walls/
35// discuss: https://leetcode.com/problems/painting-the-walls/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn paint_walls(cost: Vec<i32>, time: Vec<i32>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_2742() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.