729. Profitable Crews

Hard7.5 points estimatedArrayDynamic Programming3 hints

A film crew company has n staff members and a list of possible shoots. Shoot i needs exactly group[i] different staff members and pays profit[i]. A staff member can work on at most one shoot, so the shoots chosen together must not need more than n people in total.

A plan is any subset of the shoots (the empty plan included) whose total required staff is at most n and whose total payment is at least minProfit. Return the number of different plans, modulo 1000000007. Two plans differ if some shoot is in one and not the other.

Aim for time O(m * n * minProfit) for m shoots and space O(n * minProfit).

Example 1

Input:
n = 6minProfit = 5group = [2,3,4]profit = [4,2,3]
Output:
2
Explanation:

With 6 staff the valid plans are shoots {0,1} (5 staff, profit 6), {0,2} (6 staff, profit 7) and {0} alone has profit 4 which is below 5, so the count is 2.

Example 2

Input:
n = 4minProfit = 0group = [3,3]profit = [1,2]
Output:
3
Explanation:

With no profit requirement every plan using at most 4 staff counts: the empty plan, shoot 0 alone and shoot 1 alone, but not both, giving 3.

Constraints

1 ≤ n ≤ 100

0 ≤ minProfit ≤ 100

1 ≤ group.length = profit.length ≤ 100

1 ≤ group[i] ≤ 100, 0 ≤ profit[i] ≤ 100

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Time per case
Python 2,000 msC++ 500 msJava 1,000 msJavaScript 1,000 msTypeScript 1,000 ms

Expected complexity

Time
O(m * n * minProfit)
Space
O(n * minProfit)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…