CF1106C.Lunar New Year and Number Division

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.

There are nn positive integers a1,a2,…,ana_1, a_2, \ldots, a_n on Bob's homework paper, where nn is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least 22 numbers. Suppose the numbers are divided into mm groups, and the sum of the numbers in the jj-th group is sjs_j. Bob's aim is to minimize the sum of the square of sjs_j, that is $$\sum_{j = 1}^{m} s_j^2.$$

Bob is puzzled by this hard problem. Could you please help him solve it?

农历新年即将来临,而鲍勃正为他的家庭作业——一道数的划分问题——而苦恼。

鲍勃的作业纸上写着 nn 个正整数 a1,a2,…,ana_1, a_2, \ldots, a_n,其中 nn 总是偶数。鲍勃需要将这些数划分为若干组,且每组至少包含 22 个数。假设这些数被划分为 mm 组,第 jj 组中所有数的和为 sjs_j。鲍勃的目标是最小化所有 sjs_j 的平方和,即

∑j=1msj2.\sum_{j = 1}^{m} s_j^2.

这道难题令鲍勃十分困惑。你能帮他解决吗?

输入格式

The first line contains an even integer nn (2≤n≤3⋅1052 \leq n \leq 3 \cdot 10^5), denoting that there are nn integers on Bob's homework paper.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1041 \leq a_i \leq 10^4), describing the numbers you need to deal with.

第一行包含一个偶数 nn(2≤n≤3⋅1052 \leq n \leq 3 \cdot 10^5),表示鲍勃的作业纸上共有 nn 个整数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1041 \leq a_i \leq 10^4),描述你需要处理的数字。

输出格式

A single line containing one integer, denoting the minimum of the sum of the square of sjs_j, which is $$\sum_{i = j}^{m} s_j^2,$$ where mm is the number of groups.

一行,包含一个整数,表示 sjs_j 平方和的最小值,即 $$\sum_{i = j}^{m} s_j^2,$$ 其中 mm 为组的数量。

输入输出样例

  • 输入#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 44 numbers into 22 groups 2,8,5,3{2, 8}, {5, 3}. Thus the answer is (2+8)2+(5+3)2=164(2 + 8)^2 + (5 + 3)^2 = 164.

In the second sample, one of the optimal solutions is to divide those 66 numbers into 33 groups 1,2,1,2,1,2{1, 2}, {1, 2}, {1, 2}. Thus the answer is (1+2)2+(1+2)2+(1+2)2=27(1 + 2)^2 + (1 + 2)^2 + (1 + 2)^2 = 27.

在第一个样例中,一种最优解是将这 44 个数划分为 22 组:2,8{2, 8} 和 5,3{5, 3}。因此答案为 (2+8)2+(5+3)2=164(2 + 8)^2 + (5 + 3)^2 = 164。

在第二个样例中,一种最优解是将这 66 个数划分为 33 组:1,2{1, 2}、1,2{1, 2} 和 1,2{1, 2}。因此答案为 (1+2)2+(1+2)2+(1+2)2=27(1 + 2)^2 + (1 + 2)^2 + (1 + 2)^2 = 27。

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

首页