CF1736E.Swap and Take

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You're given an array consisting of nn integers. You have to perform nn turns.

Initially your score is 00.

On the ii-th turn, you are allowed to leave the array as it is or swap any one pair of 22 adjacent elements in the array and change exactly one of them to 00(and leave the value of other element unchanged) after swapping. In either case(whether you swap or not), after this you add aia_i to your score.

What's the maximum possible score you can get?

给你一个由 nn 个整数构成的数组。你需要执行 nn 轮操作。

初始时,你的得分为 00。

在第 ii 轮操作中,你可以选择保持数组不变,或者交换数组中任意一对相邻元素,然后在交换后将其中恰好一个元素变为 00(另一个元素的值保持不变)。无论你是否执行交换,在该轮操作结束后,你都要将 aia_i 加到你的得分上。

你所能获得的最大可能得分是多少?

输入格式

The first line contains a single integer nn (2≤n≤5002 \le n \le 500).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1061 \le a_i \le 10^6).

第一行包含一个整数 nn(2≤n≤5002 \le n \le 500)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1061 \le a_i \le 10^6)。

输出格式

Print a single integer — the maximum possible score.

输出一个整数——可能得到的最高分数。

输入输出样例

  • 输入#1

    2
    3 1

    输出#1

    6
  • 输入#2

    5
    7 3 9 6 12

    输出#2

    52

说明/提示

In the first example, to get the maximum score we do as follows. Do nothing on the first turn, add 33 to the score. Swap the first and the second elements and turn 11 to 00 on the second turn, and add 33 to the score. The final score is 66.

在第一个例子中,为获得最高得分,我们按如下方式操作:第一轮不进行任何操作,得分为 33;第二轮交换第一个和第二个元素,并将 11 变为 00,再得 33 分。最终得分为 66。

输入解题思路,AI测评打分。不知道怎么写?

首页