#P1509. 找啊找啊找GF

找啊找啊找GF

Description

sqybi now has his eye on nn MMs. Let’s number them from 11 to nn. Treating MM ii to a meal costs rmb[i]rmb[i] coins. Trying to persuade MM ii to be his GF (let’s call this "chasing" that MM) consumes rp[i]rp[i] points of "renpin" (rp). For each MM, there is a time needed to win her over, denoted time[i]time[i]. sqybi guarantees he has enough charm to win over MM ii in time[i]time[i] time ^_^.

sqybi wants to get as many MMs as possible to be his GFs, that is certain. But he does not want to spend too much time (after all, the Qixi contest problems are not finished), so among all choices that maximize the number of MMs, he wants the total time spent to be minimized.

sqybi currently has mm coins, and after some effort he has accumulated rr rp (he also earns rp by setting problems for this mock contest~~). With these coins and rp, he can chase some MMs. He wants to know the minimum total time he needs when he gets the maximum possible number of MMs.

Note that sqybi can only chase one MM at any moment—if he tries to chase two or more MMs at the same time, they will start fighting...

Input Format

The first line contains nn, the number of MMs sqybi is interested in.

Then there are nn lines, describing MMs numbered 1,2,3,,n1, 2, 3, \ldots , n. Each line has three integers: rmbrmb, rprp, and timetime.

The last line has two integers, mm and rr.

Output Format

Output a single line with one integer: the minimum total time, under the condition that the number of MMs obtained is maximized.

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

13

Hint

sqybi says: If only everything in the statement were true...

sqybi also says: If he cannot chase any MM at all, then he spends no time (that is, the time spent is 00). He will use that time to set Qixi contest problems to earn rp...

Constraints

  • For 20 % of the testdata, 1n101 \le n \le 10.
  • For 100 % of the testdata, 1rmb1001 \le rmb \le 100, 1rp1001 \le rp \le 100, 1time10001 \le time \le 1000.
  • For 100 % of the testdata, 1m,r,n1001 \le m, r, n \le 100.

Translated by ChatGPT 5