luogu#P8903. [USACO22DEC] Bribing Friends G

[USACO22DEC] Bribing Friends G

Problem Description

Bessie wants to watch the documentary: Cow Genomics, but she does not want to go alone. Unfortunately, her friends are not enthusiastic enough to go with her. So Bessie needs to bribe her friends to accompany her to the movie theater. She has two tools in her bribery arsenal: Moonies and ice cream cones.

Bessie has N(1N2000)N(1 \le N \le 2000) friends. However, not all friends are created equal. Friend ii has popularity Pi(1Pi2000)P_i(1 \le P_i \le 2000), and Bessie wants to maximize the sum of popularities of the friends who go with her. Friend ii will go with Bessie only if Bessie gives her Ci(1Ci2000)C_i(1 \le C_i \le 2000) Moonies. If Bessie gives her Xi(1Xi2000)X_i(1 \le X_i \le 2000) ice cream cones, then the friend can also give Bessie a discount of 11 Moony. Bessie can obtain any integer number of discounts from a friend, as long as these discounts do not make the friend give Moonies back to her.

Bessie has AA Moonies and BB ice cream cones available (0A,B20000 \le A,B \le 2000). Please help her find the maximum possible total popularity she can achieve if she spends her Moonies and ice cream cones in the best way.

Input Format

The first line contains three integers NN, AA, and BB, representing the number of friends Bessie has, the number of Moonies, and the number of ice cream cones.

The next NN lines each contain three integers PiP_i, CiC_i, and XiX_i, representing the popularity (PiP_i), the number of Moonies needed to bribe friend ii to accompany Bessie (CiC_i), and the number of ice cream cones needed to get a discount of 11 Moony from friend ii (XiX_i).

Output Format

Output the maximum total popularity of the friends who accompany Bessie, assuming she spends her Moonies and ice cream cones in the best way.

3 10 8
5 5 4
6 7 3
10 6 3
15

Hint

Explanation for Sample 1

Bessie can give 44 Moonies and 44 ice cream cones to cow 11, and give 66 Moonies and 33 ice cream cones to cow 33. Then cows 11 and 33 can accompany her, obtaining popularity 5+10=155+10=15.

Test Point Properties

  • Test points 242-4 satisfy N5N \le 5 and Ci=1C_i=1.
  • Test points 575-7 satisfy B=0B=0.
  • Test points 8108-10 satisfy N,A,B,Pi,Ci,Xi50N,A,B,P_i,C_i,X_i \le 50.
  • Test points 111511-15 satisfy N,A,B,Pi,Ci,Xi200N,A,B,P_i,C_i,X_i \le 200.
  • Test points 162016-20 have no additional constraints.

Translated by ChatGPT 5