#HK4109. 「BalkanOI 2023 Day2」Save the Vine!
「BalkanOI 2023 Day2」Save the Vine!
Description
An army of stinky ugly green men is set to poison the 450-year-old vine, the symbol of Maribor! They are gathering around the Kodžak monument, finalizing their plans before embarking on their march to the house on the famous Lent street on the left bank of Drava, where the venerable vine grows! You, the strong violet warrior, have been summoned to destroy the enemies before they manage to do their deadly deed!
There are a total of enemies, and each of them has three properties: stinkiness, greenness, and ugliness. For each , integers , and determine the level of stinkiness, greenness, and ugliness of the -th enemy, respectively. You, on the other hand, have two properties: strength and violetness. The integers and determine the level of your strength and violetness, respectively.
Being a proud Mariborčan / Mariborčanka, the level of your violetness () was determined at your birth and can never change. However, by defeating enemies, your strength () increases. In particular, when you defeat enemy is increased by the level of that enemy's ugliness, i.e., by . You can defeat enemies one by one in any order, but you can defeat enemy only if your strength is greater than his stinkiness () and your violetness is greater than his greenness (). Additionally, you can defeat each enemy only once.
You would surely want to know the minimum sum of your initial strength and violetness (i.e., ) that is necessary to defeat at least enemies. Write a program to find this value!
Input format
The first line contains the integers and . The -th of the following lines (for ) contains the integers , and .
Output format
Output the minimum initial value of required to defeat at least enemies.
Input bounds
- .
- .
- .
Subtasks
- (19 points) .
- (15 points) For all .
- (24 points) For all .
- (42 points) No additional constraints.
5 4
8 3 4
5 2 3
10 9 10
20 4 6
12 7 9
12
To defeat at least four enemies, it suffices to start with and . First, you defeat enemy , raising your to . Now, you can destroy enemy and achieve . With this level of strength, you can beat enemy , attaining . You complete your mission by eliminating enemy .