9589: Donkey Thinks...

内存限制:1024 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:3 通过:1

题目描述

Donkey thinks potato chips are the best food ever!

So today, when he decides to go on a long journey, he wants his backpack filled with all kinds of potato chips. He searches through the snack zone in his home and finds lots of potato chips.

To better decide which bags of potato chips to bring with him (a subset of the total bags, possibly none of them), he defines the property of a bag of chips as follows:

  • hi. The happiness this bag of chips can give to Donkey.
  • si. The space this bag of chips occupies.
  • di. The delicacy of this bag of chips.

For simplicity, we note hi,si,di as the "happiness", "space" and "delicacy" of the bag.

The total occupied space of the chosen bags can't exceed the volume of the backpack, which is V.

However, the unoccupied space may cause bumps when Donkey moves during the journey, which further causes value loss. If the chosen chips are i1,i2,,ik (k1) and the unoccupied space is U, the total value loss on account of bumps is (di1+di2++dik)×U. If you choose no bag of chips, the value loss is 0.

Considering both the advantages and disadvantages of bringing chips, the value of the whole backpack is the sum of happiness brought by these bags of chips minus the value loss. Donkey wants to maximize this value, but just can't make the decision. Help is needed for this!

输入格式

Each test contains multiple test cases. The first line contains the number of test cases T (1T104) .
Each test case consists of many lines.
The first line contains 2 integers n,V (1n105,1V500), the number of chip bags and the total volume of the bag.
Each line from the 2-nd to the (n+1)-th contains 3 integers hi,si,di (1si500,1hi,di109), the "happiness", "space" and "delicacy" of the i-th bag of chips.
It is guaranteed that n over all test cases in one test will not exceed 105, and V2 over all test cases in one test will not exceed 2.5×105.

输出格式

For each test case, output one integer: the maximum value.

输入样例 复制

2
2 5
10 2 1
2 2 100
2 5
10 2 1
2 3 100

输出样例 复制

7
12

数据范围与提示

In the first case, Donkey only chooses the first bag, resulting in a value of 10(52)×1=7.
In the second case, Donkey chooses both the first bag and the second bag, resulting in a value of 10+2(523)×(1+101)=12.
It can be proved that there are no better strategies.