#P1509. 找啊找啊找朋友

找啊找啊找朋友

Problem Description

There are nn tasks. Completing task ii requires rmbirmb_i units of budget, rpirp_i units of points, and timeitime_i units of time.

You have mm units of budget and rr units of points. Select a subset of tasks such that their total budget cost does not exceed mm and their total point cost does not exceed rr.

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 00.

Input Format

The first line contains an integer nn, representing the number of tasks.

Each of the next nn lines contains three integers rmbi,rpi,timeirmb_i,rp_i,time_i, representing the budget cost, point cost, and time required to complete task ii.

The last line contains two integers m,rm,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.

4
1 2 5
2 1 6
2 2 2
2 2 3
5 5

13

Hint

For 20%20\% of the test cases, 1n101 \le n \le 10.

For all test cases, 1n,m,r1001 \le n,m,r \le 100, 1rmbi,rpi1001 \le rmb_i,rp_i \le 100, and 1timei10001 \le time_i \le 1000.