#P10542. [THUPC 2024 决赛] RPG
[THUPC 2024 决赛] RPG
Problem Description
Xiao I is fighting the final boss in a turn-based RPG. In this battle, the main character and their teammates (that is, people in total) will act one by one in a fixed order, aiming to deal as much total damage to the boss as possible.
There are types of attack patterns in the game. The -th attack pattern deals base damage to the boss.
During actions, you can apply status effects to the boss. There are types of status effects, and at any moment the boss cannot be affected by two status effects at the same time. When the boss is under a specific status effect, using a specific attack pattern will trigger a critical hit and deal more damage. The critical hit rules are given by triples , meaning that when status effect type is applied, using attack pattern type will deal an additional damage.
At the start of the battle, the boss has no status effect. In order of actions, the -th person can take one of the following three actions:
- Use a spell to make the boss enter status effect type . If the boss previously had another status effect, the previous status effect is removed.
- Use attack pattern type to attack the boss. Regardless of whether a critical hit is triggered, after dealing damage, the boss’s status effect is removed.
- Slack off, i.e., do nothing. In this case, the boss’s status effect is kept.
As a story-focused player, Xiao I naturally does not want to calculate the optimal strategy by hand, so he throws the problem to you. You need to find the maximum total damage that can be dealt within the actions.
Input Format
The first line contains four integers , representing the number of actions, the number of critical hit rules, the number of attack pattern types, and the number of status effect types.
The second line contains integers , describing the base damage dealt by each attack pattern to the boss.
The next lines each contain two integers. Line contains , describing the options for the -th person’s action in order.
The next lines each contain three integers. Line contains $p_j, q_j, c_j (1 \le p_j \le y, 1 \le q_j \le x, 1 \le c_j \le 10^9)$, describing the -th critical hit rule. It is guaranteed that all pairs are distinct.
Output Format
Output one integer in one line, representing the maximum possible total damage dealt to the boss over the actions.
4 1 2 2
10 1
2 1
1 1
1 2
2 2
2 2 1000000000
1000000002
Hint
In the sample, there are two attack patterns and two status effects. The first attack pattern deals base damage , and the second attack pattern deals base damage . There is only one critical hit rule: under the second status effect, using the second attack pattern deals an additional damage.
The optimal strategy is as follows:
- The first person uses a spell to make the boss enter the second status effect.
- The second person slacks off, and the boss remains under the second status effect.
- The third person uses the second attack pattern, dealing base damage and critical hit damage , and the boss’s status effect is cleared.
- The fourth person uses the second attack pattern, dealing base damage .
The total damage is .
Source and Acknowledgements
From the finals of THUPC2024 (Tsinghua University Student Programming Contest and Collegiate Invitational, 2024). Thanks to THUSAA for providing this problem.
For testdata, statement, reference solution, editorial, etc., please refer to the official THUPC repository: https://thusaac.com/public.
Translated by ChatGPT 5