Codeforces--1106C--Lunar New Year and Number Division

本文介绍了Bob在农历新年临近时遇到的一道数学难题:如何将一组偶数个正整数分组,使得每组至少有两个数,并且各组内数字之和的平方和最小。通过分析,提出了解决方案——将最小值与最大值两两配对,以此达到最小化目标。给出的样例输入和输出展示了这种方法的有效性。
摘要由CSDN通过智能技术生成

题目描述:
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.

There are n positive integers a1,a2,…,an 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 sj. Bob’s aim is to minimize the sum of the square of sj, that is
∑j=1ms2j.
Bob is puzzled by this hard problem. Could you please help him solve it?
输入描述:
The first line contains an even integer n (2≤n≤3⋅105), denoting that there are n integers on Bob’s homework paper.

The second line contains n integers a1,a2,…,an (1≤ai≤104), describing the numbers you need to deal with.
输出描述:
A single line containing one integer, denoting the minimum of the sum of the square of sj, which is
∑i=jms2j,
where m is the number of groups.
输入:
4
8 5 2 3
6
1 1 1 2 2 2
输出:
164
27
题意:
给定一个n个数的序列(n为偶数) 。将数列组合为若干组。每组的数的个数至少为2。求每一组数的和平方后,所有组之和的最小值。
题解
第i小与第i大两两配对就行了。
代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值