Shadowverse is a funny card game. One day you are playing a round of this game. You have n cards, each with two attributes wi and xi. If you use card i, you will cost wi points of power and cause xi damage to the enemy. Among them, there are two special types of cards: some cards are magic cards and some have “spell boost effect”. Everytime you have used a magic card, for each unused “spell boost effect” card i: if the the current cost of i (i.e. wi) is positive, then wi will be reduced by 1. Note that some cards may be both magic cards and have spell boost effect. Now you have W points of power, you need to calculate maximum total damage you can cause.
输入解释
Input is given from Standard Input in the following format: n W w1 x1 is_magic1 is_spell_boost1 w2 x2 is_magic2 is_spell_boost2 ... ... ... wn xn is_magicn is_spell_boostn Constraints 1 ≤ n ≤ 500 0 ≤ W, wi, xi ≤ 500, and all of them are integers. is_magici means: If this card is magic card, the value is 1, otherwise the value is 0. is_spell_boosti means: If this card has spell boost effect, the value is 1, otherwise 0
输出解释
One integer representing the maximum total damage.