atcoder#ABC249F. [ABC249F] Ignore Operations
[ABC249F] Ignore Operations
Score : points
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.
5 1
2 4
2 -3
1 2
2 1
2 -3
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.
1 0
2 -1000000000
-1000000000
10 3
2 3
2 -1
1 4
2 -1
2 5
2 -9
2 2
1 -6
2 5
2 -3
15