CF1248B.Grow The Tree

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them.

The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0,0)(0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OXOX or OYOY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification.

Alexey wants to make a polyline in such a way that its end is as far as possible from (0,0)(0, 0). Please help him to grow the tree this way.

Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches.

园丁阿列克谢正在为高中生讲授竞赛编程课程。为了庆祝教师节,学生们送给他一捆木棍作为礼物,每根木棍的长度均为整数。现在阿列克谢想用这些木棍“种”出一棵树。

这棵树在平面上表现为一条由所有木棍构成的折线。该折线起始于点 (0,0)(0, 0)。在构造折线的过程中,阿列克谢将按任意顺序逐根添加木棍。每根木棍必须严格竖直或水平(即分别平行于 OYOY 轴或 OXOX 轴)。不允许两根相邻的木棍同时为水平方向或同时为竖直方向。参见下方图示以进一步理解。

阿列克谢希望构造出一条折线,使其终点距离原点 (0,0)(0, 0) 尽可能远。请帮助他以这种方式“种”出这棵树。

注意:定义树形状的折线允许自相交或自接触;但可以证明,最优解中不会出现任何自相交或自接触。

输入格式

The first line contains an integer nn (1≤n≤100 0001 \le n \le 100\,000) — the number of sticks Alexey got as a present.

The second line contains nn integers a1,…,ana_1, \ldots, a_n (1≤ai≤10 0001 \le a_i \le 10\,000) — the lengths of the sticks.

第一行包含一个整数 nn(1≤n≤100 0001 \le n \le 100\,000)—— Alexey 收到的木棍数量。

第二行包含 nn 个整数 a1,…,ana_1, \ldots, a_n(1≤ai≤10 0001 \le a_i \le 10\,000)—— 各木棍的长度。

输出格式

Print one integer — the square of the largest possible distance from (0,0)(0, 0) to the tree end.

输出一个整数——树的末端到点 (0,0)(0, 0) 的最大可能距离的平方。

输入输出样例

  • 输入#1

    3
    1 2 3

    输出#1

    26
  • 输入#2

    4
    1 1 2 2

    输出#2

    20

说明/提示

The following pictures show optimal trees for example tests. The squared distance in the first example equals 5⋅5+1⋅1=265 \cdot 5 + 1 \cdot 1 = 26, and in the second example 4⋅4+2⋅2=204 \cdot 4 + 2 \cdot 2 = 20.

以下图片展示了示例测试的最优树。第一个示例中的平方距离为 5⋅5+1⋅1=265 \cdot 5 + 1 \cdot 1 = 26,第二个示例中为 4⋅4+2⋅2=204 \cdot 4 + 2 \cdot 2 = 20。

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

首页