2809. Minimum Time to Make Array Sum At Most x Hard

@problem@discussion
#Array#Dynamic Programming#Sorting



1/**
2 * [2809] Minimum Time to Make Array Sum At Most x
3 *
4 * You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is incremented by nums2[i]. After this is done, you can do the following operation:
5 * 
6 * 	Choose an index 0 <= i < nums1.length and make nums1[i] = 0.
7 * 
8 * You are also given an integer x.
9 * Return the minimum time in which you can make the sum of all elements of nums1 to be less than or equal to x, or -1 if this is not possible.
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input: nums1 = [1,2,3], nums2 = [1,2,3], x = 4
14 * Output: 3
15 * Explanation: 
16 * For the 1st second, we apply the operation on i = 0. Therefore nums1 = [0,2+2,3+3] = [0,4,6]. 
17 * For the 2nd second, we apply the operation on i = 1. Therefore nums1 = [0+1,0,6+3] = [1,0,9]. 
18 * For the 3rd second, we apply the operation on i = 2. Therefore nums1 = [1+1,0+2,0] = [2,2,0]. 
19 * Now sum of nums1 = 4. It can be shown that these operations are optimal, so we return 3.
20 * 
21 * <strong class="example">Example 2:
22 * 
23 * Input: nums1 = [1,2,3], nums2 = [3,3,3], x = 4
24 * Output: -1
25 * Explanation: It can be shown that the sum of nums1 will always be greater than x, no matter which operations are performed.
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	<font face="monospace">1 <= nums1.length <= 10^3</font>
31 * 	1 <= nums1[i] <= 10^3
32 * 	0 <= nums2[i] <= 10^3
33 * 	nums1.length == nums2.length
34 * 	0 <= x <= 10^6
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/minimum-time-to-make-array-sum-at-most-x/
40// discuss: https://leetcode.com/problems/minimum-time-to-make-array-sum-at-most-x/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn minimum_time(nums1: Vec<i32>, nums2: Vec<i32>, x: i32) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2809() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.