#P8888. [DMOI-R1] 实验基地
[DMOI-R1] 实验基地
Background
Little A and Little B had an epic rookie battle using the brand-new equipment of the experimental base.
Problem Description
As everyone knows, weapons in the experimental base are disposable. Now, Little A picks different weapons, and Little B also gets different weapons. Each person’s weapons can be numbered from to or in order, and they will use the weapons one by one in this order.
The experimental warehouse records the firepower of all weapons. Little A’s -th weapon can release energy, and Little B’s -th weapon can release energy. In particular, when Little A’s -th weapon and Little B’s -th weapon are used at the same time, they will additionally release energy. Due to the special effects of some indescribable combinations, , , and may all be less than .
When someone uses a weapon for the first time, the battle officially starts, which is counted as the -st second, until after someone has finished using weapons and then nobody uses any weapon anymore; denote that moment as the -th second ( is not part of the input). That is, at the -st second and the -th second, at least one person must use a weapon, and during seconds to , under the other constraints, each second both sides may choose to use the next weapon in order or not use a weapon.
To avoid killing the opponent, neither side necessarily uses all weapons.
Because the experimental base has power generators, if Little A does not continuously use weapons to release energy but rests for seconds, then they will absorb energy. Similarly, if Little B pauses for seconds, they will absorb energy. If weapons are released in two consecutive seconds, the interval is seconds, and so on.
To prevent the base from being nuked, you need to compute the maximum possible total energy that may be released after the battle ends (it may be negative).
If you are confused about the details, please read the additional explanations in the hint first.
Input Format
The first line contains two numbers and .
The second line contains numbers, where the -th number is .
The third line contains numbers, where the -th number is .
Next are lines, each containing numbers. The number in row and column is .
The last line contains four non-negative integers .
Output Format
Only one line. Output one number, the maximum possible energy.
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
1 0 1 0
45
4 4
-2 -2 -2 -2
2 3 4 9
4 -2 0 4
0 0 0 0
-1 0 1 0
0 0 2 0
1 2 1 0
15
Hint
-
The battle start time (the -st second) is the time when either side first releases their first skill. The battle end time is the time when either side releases the last skill. The end time is not fixed.
-
Skills must be released in order, but they do not have to be all released during the battle.
-
, , and can be negative, so the total energy may be negative. “Absorbing energy” means the total energy decreases by or , i.e. during an interval, the total energy always decreases, and the longer the time, the more it decreases.
-
The I/O size of this problem is large, so it is recommended to use an appropriate input method.
Sample Explanation:
Sample 1: Each person uses their weapons numbered from to in order from the -st to the -th second to obtain the maximum value.
Sample 2: Little B uses their weapons numbered from to in order from the -st to the -th second, and Little A uses their weapon at the -th second to obtain the maximum value. The energy released by single weapons is , the collision releases units of energy, and Little A absorbs units of energy in the first seconds.
Constraints:
| Subtask | Score | ||
|---|---|---|---|
This problem uses bundled tests. You can get the score of a subtask only if you pass all test points in that subtask.
For of the testdata: , .
Translated by ChatGPT 5