QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#8877. Nutella 的生活

Statistics

网站 chefforces.at 刚刚发布了明年的比赛日程!日程表上有 $n$ 场比赛,且不会有任何变动。Oleg 非常兴奋,并决定最大化他的乐趣值。

经过对每场比赛出题人的深入分析,Oleg 为每场比赛确定了一个整数 $a_i$。数字 $a_i$ 是 Oleg 参加第 $i$ 场比赛所能获得的乐趣值。注意,由于某种众所周知的巧合,一些 $a_i$ 可能是负数。

然而,Oleg 不想错过比赛,尤其是连续错过多场比赛。形式化地说,如果 Oleg 决定跳过一场比赛,且他在此之前已经连续跳过了 $x$ 场比赛,那么他的总乐趣值会减少 $x + 1$。

最后,Oleg 希望每一场比赛的乐趣值都至少不低于他之前参加过的上一场比赛。换句话说,如果 Oleg 参加了编号为 $i$ 和 $j$ 的比赛,且 $i < j$,则必须满足条件 $a_i \le a_j$。

请帮助 Oleg 决定他应该参加哪些比赛,以使总乐趣值最大化。

输入格式

第一行包含一个整数 $n$,表示日程表中的比赛场数 ($1 \le n \le 10^5$)。 第二行包含 $n$ 个整数 $a_i$ ($-10^9 \le a_i \le 10^9$)。

输出格式

输出仅一行,包含一个整数:Oleg 能获得的最大乐趣值。

样例

样例输入 1

7
1 3 2 7 3 2 4

样例输出 1

7

样例输入 2

7
-3 -4 -2 -2 -6 -8 -1

样例输出 2

-11

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.