Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
高橋君は 匹のモンスターに順に出会います。 匹目 のモンスターの強さは です。
高橋君はそれぞれのモンスターについて逃がすか倒すか選ぶことができます。
高橋君はそれぞれの行動によって次のように経験値を得ます。
- モンスターを逃がした場合、得られる経験値は である。
- 強さが のモンスターを倒したとき、経験値を 得る。
ただし、モンスターを倒すのが偶数回目(, , 回目)であるとき、さらに追加で経験値を 得る。
匹から高橋君が得た経験値の合計としてあり得る最大の値を求めてください。
制約
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
匹から高橋君が得た経験値の合計としてあり得る最大の値を整数で出力せよ。
入力例 1Copy
5 1 5 3 2 7
出力例 1Copy
28
匹目のモンスターを倒して、 匹目のモンスターを逃したとき、高橋君は次のように経験値を得ます。
- 強さが のモンスターを倒す。高橋君は の経験値を得る。
- 強さが のモンスターを倒す。高橋君は の経験値を得る。モンスターを倒すのは 回目であるため、追加で経験値 を得る。
- 強さが のモンスターを倒す。高橋君は の経験値を得る。
- 匹目のモンスターを逃がす。高橋君は経験値を得ない。
- 強さが のモンスターを倒す。高橋君は の経験値を得る。モンスターを倒すのは 回目であるため、追加で経験値 を得る。
よって、このとき の経験値を得ます。
出会ったモンスターであっても、逃がした場合は倒した回数には数えられないことに注意してください。
高橋君がどのように行動しても得られる経験値は 以下であるため、 を出力します。
なお、この場合においてすべてのモンスターを倒した時に得られる経験値は となります。
入力例 2Copy
2 1000000000 1000000000
出力例 2Copy
3000000000
答えが bit 整数型に収まらない可能性があることに注意してください。
Score : points
Problem Statement
Takahashi will encounter monsters in order. The -th monster has a strength of .
For each monster, he can choose to either let it go or defeat it.
Each action awards him experience points as follows:
- If he lets a monster go, he gains experience points.
- If he defeats a monster with strength , he gains experience points.
If it is an even-numbered defeated monster (2nd, 4th, ...), he gains an additional experience points.
Find the maximum total experience points he can gain from the monsters.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the maximum total experience points he can gain from the monsters as an integer.
Sample Input 1Copy
5 1 5 3 2 7
Sample Output 1Copy
28
If Takahashi defeats the 1st, 2nd, 3rd, and 5th monsters, and lets the 4th monster go, he gains experience points as follows:
- Defeats a monster with strength . He gains experience point.
- Defeats a monster with strength . He gains experience points. As it is the 2nd defeated monster, he gains an additional points.
- Defeats a monster with strength . He gains experience points.
- Lets the 4th monster go. Takahashi gains no experience points.
- Defeats a monster with strength . He gains experience points. As it is the 4th defeated monster, he gains an additional points.
Therefore, in this case, he gains experience points.
Note that even if he encounters a monster, if he lets it go, it does not count as defeated.
He can gain at most experience points no matter how he acts, so print .
As a side note, if he defeats all monsters in this case, he would gain experience points.
Sample Input 2Copy
2 1000000000 1000000000
Sample Output 2Copy
3000000000
Beware that the answer may not fit in a -bit integer.