QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#5122. 奇怪的和

Statistiques

给定一个序列 $a_1, a_2, \dots, a_n$。

你需要选择零个或多个 $a$ 中的元素,使得:如果你选择了 $a_i$,那么在任何长度为 $i$ 的区间内(形式化地,对于任何 $1 \le j \le n - i + 1$,在 $a[j, j + i - 1]$ 中),你最多只能选择 2 个元素。

计算你所选元素的最大和。

输入格式

第一行包含一个整数 $n$ ($2 \le n \le 10^5$)。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$)。

输出格式

输出一个整数,表示答案。

样例

样例输入 1

4
1 4 3 2

样例输出 1

7

样例输入 2

3
-10 -10 -10

样例输出 2

0

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.