BackmediumUncategorized uncategorized medium

Maximum Subset with Three Resource Constraints Solution

Problem Statement

You are given three integers `R1`, `R2`, and `R3`, representing the maximum available units of three different resources. You are also given a 2D integer array `demands` of size `n` where `demands[i] = [r1_i, r2_i, r3_i]` represents the required units of the three resources to satisfy the `i`-th demand. Return the maximum number of demands you can satisfy such that the total resources used do not exceed `R1`, `R2`, and `R3` respectively.

Example 1
Input
R1 = 5 R2 = 4 R3 = 3 demands = [[2, 1, 1], [1, 2, 1], [3, 2, 2]]
Output
undefined

Explanation: We can satisfy the first two demands [2, 1, 1] and [1, 2, 1], requiring a total of [3, 3, 2] resources, which does not exceed [5, 4, 3].

Constraints

  • 1 <= demands.length <= 50
  • demands[i].length == 3
  • 0 <= demands[i][j] <= 50
  • 0 <= R1, R2, R3 <= 50
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free