Profitable Schemes - Problem
Criminal Organization Planning Challenge

You're managing a criminal organization with n members who need to plan their operations strategically. You have a list of potential crimes, where each crime i:
• Generates profit[i] money
• Requires exactly group[i] members to execute

Important constraint: Each member can only participate in one crime - no member can be involved in multiple operations.

Your goal is to find how many different profitable schemes exist. A profitable scheme is any combination of crimes that:
1. Generates at least minProfit total profit
2. Uses at most n total members

Since the answer can be extremely large, return it modulo 10^9 + 7.

Example: With 3 members, minProfit=2, profits=[2,3,1], groups=[2,1,1]
You could choose crime 0 (profit=2, uses 2 members) OR crimes 1+2 (profit=4, uses 2 members) = 2 schemes

Input & Output

example_1.py — Basic Case
$ Input: n = 5, minProfit = 3, group = [2,2], profit = [2,3]
Output: 2
💡 Note: We can form 2 profitable schemes: choose crime 1 alone (profit=3, members=2) OR choose both crimes (profit=5, members=4). Both satisfy minProfit ≥ 3 and members ≤ 5.
example_2.py — Multiple Options
$ Input: n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]
Output: 7
💡 Note: Multiple combinations work: {0}, {1}, {2}, {0,1}, {0,2}, {1,2}, {0,1,2}. Each achieves profit ≥ 5 with members ≤ 10.
example_3.py — Edge Case
$ Input: n = 1, minProfit = 1, group = [1,1,1], profit = [1,1,1]
Output: 3
💡 Note: With only 1 member available, we can choose any single crime. Each crime uses exactly 1 member and generates profit 1, meeting our minimum requirement.

Constraints

  • 1 ≤ n ≤ 100
  • 0 ≤ minProfit ≤ 100
  • 1 ≤ group.length ≤ 100
  • 1 ≤ group[i] ≤ 100
  • 0 ≤ profit[i] ≤ 100
  • Note: Each member can participate in at most one crime

Visualization

Tap to expand
Profitable Schemes - Dynamic Programming INPUT n = 5 members available 1 2 3 4 5 minProfit = 3 Available Crimes Crime 0 group[0] = 2 members profit[0] = 2 Crime 1 group[1] = 2 members profit[1] = 3 group = [2, 2] profit = [2, 3] Need profit >= 3 ALGORITHM STEPS 1 Define DP State dp[i][j][k] = schemes using i crimes, j members, k profit 2 Initialize Base dp[0][0] = 1 (empty scheme) 3 Transition For each crime: include or skip 4 Sum Valid Schemes Count where profit >= minProfit Valid Combinations: Crime 1 only: 2 members, profit=3 [OK] Crime 0 + Crime 1: 4 members, profit=5 [OK] Crime 0 only: profit=2 < 3 (Not enough profit) FINAL RESULT Profitable Schemes Found: 2 Valid Schemes: Scheme 1: Crime 1 Members: 2 of 5 Profit: 3 >= 3 [OK] Scheme 2: Crime 0 + 1 Members: 4 of 5 Profit: 5 >= 3 [OK] Output: 2 Key Insight: Use 3D DP where dp[members][profit] tracks the number of ways to achieve each state. For each crime, we either skip it (keep current state) or take it (add members, add profit). Profit dimension is capped at minProfit since any excess still counts. Result: mod 10^9+7. TutorialsPoint - Profitable Schemes | Dynamic Programming Approach
Asked in
Google 45 Amazon 38 Meta 32 Microsoft 28
42.3K Views
Medium Frequency
~25 min Avg. Time
1.2K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen