P1509 Find, Find, Find a Friend

Description

There are $n$ tasks. Completing task $i$ requires $rmb_i$ units of budget, $rp_i$ units of points, and $time_i$ units of time. You have $m$ units of budget and $r$ units of points. Select a subset of tasks such that their total budget cost does not exceed $m$ and their total point cost does not exceed $r$. Your primary objective is to maximize the number of completed tasks. Among all selections containing the maximum possible number of tasks, minimize the total time required. Output this minimum total time. If no task can be completed, output $0$.

Input Format

The first line contains an integer $n$, representing the number of tasks. Each of the next $n$ lines contains three integers $rmb_i,rp_i,time_i$, representing the budget cost, point cost, and time required to complete task $i$. The last line contains two integers $m,r$, representing the available budget and points.

Output Format

Output one integer: the minimum total time among all selections containing the maximum possible number of tasks.

Explanation/Hint

For $20\%$ of the test cases, $1 \le n \le 10$. For all test cases, $1 \le n,m,r \le 100$, $1 \le rmb_i,rp_i \le 100$, and $1 \le time_i \le 1000$.