A12284 | Lunar New Year and Number Division
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.
There are $n$ positive integers $a_1, a_2, \ldots, a_n$ on Bob's homework paper, where $n$ is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least $2$ numbers. Suppose the numbers are divided into $m$ groups, and the sum of the numbers in the $j$ -th group is $s_j$ . Bob's aim is to minimize the sum of the square of $s_j$ , that is $\sum_{j = 1}^{m} s_j^2.$
Bob is puzzled by this hard problem. Could you please help him solve it?
There are $n$ positive integers $a_1, a_2, \ldots, a_n$ on Bob's homework paper, where $n$ is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least $2$ numbers. Suppose the numbers are divided into $m$ groups, and the sum of the numbers in the $j$ -th group is $s_j$ . Bob's aim is to minimize the sum of the square of $s_j$ , that is $\sum_{j = 1}^{m} s_j^2.$
Bob is puzzled by this hard problem. Could you please help him solve it?
输入格式
The first line contains an even integer $n$ ( $2 \leq n \leq 3 \cdot 10^5$ ), denoting that there are $n$ integers on Bob's homework paper.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^4$ ), describing the numbers you need to deal with.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^4$ ), describing the numbers you need to deal with.
输出格式
A single line containing one integer, denoting the minimum of the sum of the square of $s_j$ , which is $$$$\sum_{i = j}^{m} s_j^2, $$ where $m$$$ is the number of groups.
输入输出样例
输入 #1
4 8 5 2 3
输出 #1
164
输入 #2
6 1 1 1 2 2 2
输出 #2
27
In the first sample, one of the optimal solutions is to divide those $4$ numbers into $2$ groups $\{2, 8\}, \{5, 3\}$ . Thus the answer is $(2 + 8)^2 + (5 + 3)^2 = 164$ .
In the second sample, one of the optimal solutions is to divide those $6$ numbers into $3$ groups $\{1, 2\}, \{1, 2\}, \{1, 2\}$ . Thus the answer is $(1 + 2)^2 + (1 + 2)^2 + (1 + 2)^2 = 27$ .
In the second sample, one of the optimal solutions is to divide those $6$ numbers into $3$ groups $\{1, 2\}, \{1, 2\}, \{1, 2\}$ . Thus the answer is $(1 + 2)^2 + (1 + 2)^2 + (1 + 2)^2 = 27$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted