#P2198. 杀蚂蚁

杀蚂蚁

Description

After Little FF’s research, he found that the ants always attack along the same route of length nn units, and the time needed to traverse one unit length is TT seconds. In other words, as long as Little FF deploys defenses along this route and inflicts heavy damage on the ants, he can stop their advance.

SCV specializes in building three kinds of defense towers: Laser Tower, Radiation Tower, and Interference Tower. On each unit length, exactly one tower can be built. Their effects are as follows:

Laser Tower: Uses high-energy lasers and deals rr damage per second to the ants while they pass in front of the tower.

Radiation Tower: Releases radioactive elements. After the ants pass this tower, they take gg damage per second.

Interference Tower: Disrupts the ants’ pheromones. After the ants pass this tower, the time to traverse each subsequent unit length becomes T+bT + b.

The effects of Radiation Towers and Interference Towers stack. That is, if the enemy has passed xx Radiation Towers, then they take x×gx \times g damage per second; similarly, if they have passed yy Interference Towers, then the time to traverse one unit length becomes T+y×bT + y \times b.

There is enough time before the next wave of attacks. As the chief engineer of the “NewBe_One” project, now appointed as the chief strategist, you must design a tower placement plan that maximizes the total damage dealt to the ants.

Input Format

The input contains a single line with 55 integers n,r,g,b,Tn, r, g, b, T separated by a space. They represent: the total route length you can deploy on nn, the Laser Tower’s per-second damage rr, the Radiation Tower’s per-second damage gg, the Interference Tower’s per-unit time increase bb, and the base time per unit length TT.

Output Format

Output a single integer, the maximum total damage your plan can deal to the enemy.

5 4 3 2 1
82

Hint

Sample Explanation

At position 11 build a Radiation Tower; at positions 22 and 33 build Interference Towers; at positions 44 and 55 build Laser Towers.

Constraints

For 30%30\% of the testdata: 1n201 \leq n \leq 20.

For 60%60\% of the testdata: $1 \leq n \leq 1024, 0 \leq r,g,b \leq 65536, 0 \leq T \leq 3$.

For the remaining 40%40\% of the testdata: $1 \leq n \leq 400, 0 \leq r,g,b \leq 2^{31}-1, 0 \leq T \leq 1000$.

Translated by ChatGPT 5