Tap here to switch tabs
Problem
Submissions

Problem: Zero Array Transformation IV

Try to solve the Zero Array Transformation IV problem.

Statement

You are given an integer array nums and an array queries, where queries[i] = [l_i, r_i, val_i].

For each query queries[i], you can choose any subset of indices within the range [li,ri][l_i, r_i] and decrease the value at each selected index by valival_i.

An array is considered a Zero Array if every element in the array is equal to 00.

Return the minimum integer kk (0≤k≤0 \leq k \leq queries.length) such that after applying the first kk queries, nums can be transformed into a Zero Array. If it is impossible to transform nums into a Zero Array even after applying all queries, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤10\leq 10

  • 0≤0 \leq nums[i] ≤1000\leq 1000

  • 1≤1 \leq queries.length ≤1000\leq 1000

  • queries[i] =[li,ri,vali]= [l_i, r_i, val_i]

  • 0≤li≤ri<0 \leq l_i \leq r_i < nums.length

  • 1≤vali≤101 \leq val_i \leq 10

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Zero Array Transformation IV

Try to solve the Zero Array Transformation IV problem.

Statement

You are given an integer array nums and an array queries, where queries[i] = [l_i, r_i, val_i].

For each query queries[i], you can choose any subset of indices within the range [li,ri][l_i, r_i] and decrease the value at each selected index by valival_i.

An array is considered a Zero Array if every element in the array is equal to 00.

Return the minimum integer kk (0≤k≤0 \leq k \leq queries.length) such that after applying the first kk queries, nums can be transformed into a Zero Array. If it is impossible to transform nums into a Zero Array even after applying all queries, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤10\leq 10

  • 0≤0 \leq nums[i] ≤1000\leq 1000

  • 1≤1 \leq queries.length ≤1000\leq 1000

  • queries[i] =[li,ri,vali]= [l_i, r_i, val_i]

  • 0≤li≤ri<0 \leq l_i \leq r_i < nums.length

  • 1≤vali≤101 \leq val_i \leq 10