#P10303. [THUWC 2020] 报告顺序

[THUWC 2020] 报告顺序

Problem Description

Today, Yazid is going to listen to nn people giving reports. For convenience, we number these people from 11 to nn.

Yazid has an excitement level, initially ss, and this value will change as the reports go on.

The report of person ii (1in1\leq i\leq n) can be described by three numbers ai,bi,cia_i,b_i,c_i. This means that if, before listening to their report, Yazid’s excitement level is xx, then after listening to it, Yazid’s excitement level will become ax+bx+ca\lvert x\rvert+bx+c.

Yazid also needs to take final exams, so he wants to be as excited as possible after listening to all the reports. Therefore, your task is to help Yazid decide the order of all reports so that Yazid’s excitement level is maximized after everyone has finished presenting.

Input Format

The first line contains two integers n,sn,s separated by spaces.

The next nn lines describe the nn people’s reports. Line ii of this part contains three integers ai,bi,cia_i,b_i,c_i separated by spaces.

Output Format

Output one integer in one line, representing the maximum excitement level Yazid can have after listening to all the reports.

2 3
0 1 1
0 2 0

8

1 -2
8 -4 1

25

Hint

[Sample Explanation #1]

If Yazid listens to the first person’s report first, and then the second person’s report, the final excitement level is (3+1)×2=8(3+1)\times2=8.

If Yazid listens to the second person’s report first, and then the first person’s report, the final excitement level is (3×2)+1=7(3\times 2)+1=7.

So the maximum excitement level is 88.

[Sample Explanation #2]

There is only one report. Yazid’s initial excitement level is 2-2, so after listening to the report, the excitement level is 8×2+(4)×(2)+1=258\times \lvert -2 \rvert+(-4)\times (-2)+1=25.

[Subtasks]

Subtask 1 (13 points): n10n \le 10.

Subtask 2 (19 points): ci=0c_i = 0.

Subtask 3 (23 points): ai=0a_i=0.

Subtask 4 (45 points): no special constraints.

For all testdata, it is guaranteed that n15n\leq 15, and the absolute values of a,b,c,sa,b,c,s are all at most 1515.

[Hint]

Under the constraints, the answer will not exceed the range of a 128-bit signed integer, so you may try using __int128 to help implement your algorithm.

Translated by ChatGPT 5