#abc249f. F - Ignore Operations
F - Ignore Operations
Score : points
问题描述
Takahashi 持有一个整数 。初始时,。
有 个操作。第 个操作 由两个整数 和 表示,如下所示:
- 若 ,则将 替换为 。
- 若 ,则将 替换为 。
Takahashi 可以跳过任意从 到 (包括 和 )的若干个操作。当他按照原顺序仅执行剩余的操作一次时,找出 的最大可能最终值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has an integer . Initially, .
There are operations. The -th operation is represented by two integers and as follows:
- If , replace with .
- If , replace with .
Takahashi may skip any number between and (inclusive) of the operations. When he performs the remaining operations once each without changing the order, find the maximum possible final value of .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5 1
2 4
2 -3
1 2
2 1
2 -3
Sample Output 1
3
If he skips the -th operation, changes as $0 \rightarrow 4 \rightarrow 1 \rightarrow 2 \rightarrow 3$, so results in . This is the maximum.
Sample Input 2
1 0
2 -1000000000
Sample Output 2
-1000000000
Sample Input 3
10 3
2 3
2 -1
1 4
2 -1
2 5
2 -9
2 2
1 -6
2 5
2 -3
Sample Output 3
15
update @ 2024/3/10 10:39:20