#abc306d. D - Poisonous Full-Course
D - Poisonous Full-Course
Score : points
问题描述
Takahashi 决定在一家餐厅享用由 道菜组成的全套有线餐。
第 道菜为:
- 如果 ,则是一道美味度为 的解毒菜品;
- 如果 ,则是一道美味度为 的有毒菜品。
当 Takahashi 吃一道菜时,他的状态会发生如下变化:
- 最初,Takahashi 拥有健康的胃。
- 当他拥有健康胃部时,
- 如果他吃了解毒菜品,胃部将保持健康;
- 如果他吃了有毒菜品,他会胃部不适。
- 当他拥有胃部不适时,
- 如果他吃了解毒菜品,胃部会恢复健康;
- 如果他吃了有毒菜品,他将死亡。
用餐过程如下。
- 按照 的顺序依次重复以下过程。
- 首先,向 Takahashi 端上第 道菜。
- 接下来,他选择“吃”或“跳过”这道菜。
- 如果他选择“吃”,则吃掉第 道菜。他的状态也会根据所吃菜品发生变化。
- 如果他选择“跳过”,则不食用第 道菜。这道菜之后不能再端上或以某种方式保留。
- 最后,(如果状态发生变化,在变化后)如果他还未死亡,
- 若 ,他进入下一道菜。
- 若 ,他成功活着离开餐厅。
由于有一个重要的会议在等待着他,所以他必须确保活着离开。
在上述条件下,当他决定是否“吃”或“跳过”每道菜时,找出他所吃菜品的最大可能美味度之和(若他什么都没吃,则为 )。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has decided to enjoy a wired full-course meal consisting of courses in a restaurant.
The -th course is:
- if , an antidotal course with a tastiness of ;
- if , a poisonous course with a tastiness of .
When Takahashi eats a course, his state changes as follows:
- Initially, Takahashi has a healthy stomach.
- When he has a healthy stomach,
- if he eats an antidotal course, his stomach remains healthy;
- if he eats a poisonous course, he gets an upset stomach.
- When he has an upset stomach,
- if he eats an antidotal course, his stomach becomes healthy;
- if he eats a poisonous course, he dies.
The meal progresses as follows.
- Repeat the following process for in this order.
- First, the -th course is served to Takahashi.
- Next, he chooses whether to "eat" or "skip" the course.
- If he chooses to "eat" it, he eats the -th course. His state also changes depending on the course he eats.
- If he chooses to "skip" it, he does not eat the -th course. This course cannot be served later or kept somehow.
- Finally, (if his state changes, after the change) if he is not dead,
- if , he proceeds to the next course.
- if , he makes it out of the restaurant alive.
An important meeting awaits him, so he must make it out of there alive.
Find the maximum possible sum of tastiness of the courses that he eats (or if he eats nothing) when he decides whether to "eat" or "skip" the courses under that condition.
Constraints
- All input values are integers.
-
- In other words, is either or .
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
5
1 100
1 300
0 -200
1 500
1 300
Sample Output 1
600
The following choices result in a total tastiness of the courses that he eats amounting to , which is the maximum possible.
- He skips the -st course. He now has a healthy stomach.
- He eats the -nd course. He now has an upset stomach, and the total tastiness of the courses that he eats amounts to .
- He eats the -rd course. He now has a healthy stomach again, and the total tastiness of the courses that he eats amounts to .
- He eats the -th course. He now has an upset stomach, and the total tastiness of the courses that he eats amounts to .
- He skips the -th course. He now has an upset stomach.
- In the end, he is not dead, so he makes it out of the restaurant alive.
Sample Input 2
4
0 -1
1 -2
0 -3
1 -4
Sample Output 2
0
For this input, it is optimal to eat nothing, in which case the answer is .
Sample Input 3
15
1 900000000
0 600000000
1 -300000000
0 -700000000
1 200000000
1 300000000
0 -600000000
1 -900000000
1 600000000
1 -100000000
1 -400000000
0 900000000
0 200000000
1 -500000000
1 900000000
Sample Output 3
4100000000
The answer may not fit into a -bit integer type.
update @ 2024/3/10 08:38:58