#P16404. [ECUSTPC 2026 Spring] 海底捞月
[ECUSTPC 2026 Spring] 海底捞月
Background
:::epigraph ___, ___ frowned: What does it mean to fish at the bottom of the river? :::
Problem Description
TSUCE's final exam is over. The grader, Big K, looked at Little T's terrible paper.
So he decided to use the following moves to save Little T, who scored points:
- 【Pull Up by the Roots】. This move can be used at most times. It updates Little T's current score by taking the square root, multiplying by , and rounding down, i.e., .
- 【Thirty-Seventy Split】. This move can be used at most times. It updates Little T's current score by multiplying by , adding , and rounding down, i.e., .
- 【Plant Five, Get Six】. This move can be used at most times. It updates Little T's current score by multiplying by and rounding down, i.e., .
- 【Five Blessings at the Door】. This move can be used at most times. It updates Little T's current score by adding , i.e., .
The four moves can be used in any order. Please help Big K find a reasonable way to use these moves so that Little T gets the highest possible score.
Input Format
The first line contains an integer , which indicates the number of testdata.
Each testdata consists of one line with integers $x, a_1, a_2, a_3, a_4\ (1 \le x \le 100, 0 \le a_1, a_2, a_3, a_4 \le 400)$, which represent Little T's initial score and the maximum number of times each of the four moves can be used.
Output Format
For each testdata, output one line with one integer, representing the highest score Little T can achieve.
7
1 1 1 1 1
50 2 1 1 2
99 0 1 2 1
10 2 0 0 3
100 400 400 400 400
75 1 7 3 0
1 3 7 4 3
70
118
148
71
98703086085238798121046930830507710
168
232
Hint
Sample 1 Explanation
For the -st testdata, Little T starts with a great score of point. Big K can use each move at most once. Big K can use the following strategy:
- First use 【Thirty-Seventy Split】, and Little T becomes $\lfloor 0.7x + 30 \rfloor = \lfloor 0.7 \times 1 + 30 \rfloor = 30$ points.
- Then use 【Pull Up by the Roots】, and Little T becomes $\lfloor 10\sqrt{x} \rfloor = \lfloor 10\sqrt{30} \rfloor = 54$ points.
- Then use 【Five Blessings at the Door】, and Little T becomes points.
- Then use 【Plant Five, Get Six】, and Little T becomes $\lfloor 1.2x \rfloor = \lfloor 1.2 \times 59 \rfloor = 70$ points.
Translated by ChatGPT 5