#C6361. Taco: Maximum Project Profit
Taco: Maximum Project Profit
Taco: Maximum Project Profit
You are given a set of projects, each project having a required time and a profit associated with it. You need to choose a subset of projects to maximize the total profit without exceeding the allotted total hours.
The problem can be formalized as follows:
Given two arrays: ( T = [t_1, t_2, \dots, t_n] ) and ( P = [p_1, p_2, \dots, p_n] ), and a total available time ( H ), choose a subset of indices ( I \subseteq {1, 2, \dots, n} ) such that
( \sum_{i \in I} t_i \le H ) and the profit ( \sum_{i \in I} p_i ) is maximized.
Example: For ( T = [2, 3, 5, 7] ), ( P = [10, 15, 20, 25] ), and ( H = 8 ), the maximum profit is 35.
inputFormat
The input is read from stdin
and has the following format:
- An integer n representing the number of projects.
- If n > 0, a line with n space-separated integers representing the time required for each project.
- If n > 0, a line with n space-separated integers representing the profit of each project.
- An integer H representing the total available hours.
Note: For the case where n = 0, the two lines for times and profits will be empty.
outputFormat
Output the maximum profit achievable without exceeding the total available hours. The answer is printed to stdout
.## sample
4
2 3 5 7
10 15 20 25
8
35