TopCoder

Caido
主唱太拼命了

User's AC Ratio

90.9% (10/11)

Submission's AC Ratio

41.9% (13/31)

Tags

Description

小瓏和小月一共要吃掉 n 個快過期的西瓜,吃愈多西瓜可能會愈快樂,但也可能會愈不舒服。小瓏評估自己吃掉 x 個西瓜的快樂值是 A1x2+B1x+C1,小月評估自己吃掉 x 個西瓜的快樂值是 A2x2+B2x+C2,兩人想要分配這些西瓜使得他們吃完這些西瓜的總快樂值最大。請你回答這個最大總快樂值。西瓜一定要被吃完而不能丟掉。

Input Format

輸入有三行,第一行是小瓏的快樂係數 A1,B1,C1,第二行是小月的快樂係數 A2,B2,C2,第三行是一個整數 n 表示西瓜數量,數字間以空白分隔。

輸入保證 1n1001000A1,B1,C1,A2,B2,C21000
其中 50% 的測資保證 n=2

Output Format

輸出一行一個整數表示最大總快樂度。

Sample Input 1

3 -1 4
-2 5 1
2

Sample Output 1

15

Sample Input 2

-4 3 5
7 -8 0
5

Sample Output 2

140

Hints

Problem Source

APCS 歷屆改編

Subtasks

No. Testdata Range Constraints Score
1 0~1 範例測資 0
2 2~9 n=2 50
3 0~25 無額外限制 50

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 524288 65536 1 3
1 1000 524288 65536 1 3
2 1000 524288 65536 2 3
3 1000 524288 65536 2 3
4 1000 524288 65536 2 3
5 1000 524288 65536 2 3
6 1000 524288 65536 2 3
7 1000 524288 65536 2 3
8 1000 524288 65536 2 3
9 1000 524288 65536 2 3
10 1000 524288 65536 3
11 1000 524288 65536 3
12 1000 524288 65536 3
13 1000 524288 65536 3
14 1000 524288 65536 3
15 1000 524288 65536 3
16 1000 524288 65536 3
17 1000 524288 65536 3
18 1000 524288 65536 3
19 1000 524288 65536 3
20 1000 524288 65536 3
21 1000 524288 65536 3
22 1000 524288 65536 3
23 1000 524288 65536 3
24 1000 524288 65536 3
25 1000 524288 65536 3