CF863B.Kayaking
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·n people in the group (including Vadim), and they have exactly n - 1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. i-th person's weight is w__i, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.
Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.
Help the party to determine minimum possible total instability!
瓦季姆非常热衷于旅行。最近,他听说了家乡附近有一项皮划艇活动,对此兴奋不已,于是加入了一个皮划艇爱好者团体。
现在,该团体已准备好启程,但首先需要选择皮划艇。团体中共有 2⋅n 人(包括瓦季姆),他们恰好有 n−1 艘双人皮划艇(每艘显然可载两人)和 2 艘单人皮划艇。第 i 个人的体重为 wi;而在皮划艇运动中,体重是一个关键因素——若同乘一艘双人皮划艇的两人体重相差过大,则可能导致翻船。当然,大家希望以某种方式安排座位,从而最小化皮划艇翻船的可能性。
形式化地定义:单人皮划艇的“不稳定性”恒为 0;而双人皮划艇的“不稳定性”则等于艇上两人体重之差的绝对值。整个旅程的“不稳定性”即为所有皮划艇不稳定性之和。
请帮助该团体确定可能的最小总不稳定性!
输入格式
The first line contains one number n (2 ≤ n ≤ 50).
The second line contains 2·n integer numbers _w_1, _w_2, ..., w_2_n, where w__i is weight of person i (1 ≤ w__i ≤ 1000).
第一行包含一个整数 n(2 ≤ n ≤ 50)。
第二行包含 2⋅n 个整数 w1,w2,…,w2n,其中 wi 表示第 i 个人的体重(1 ≤ wi ≤ 1000)。
输出格式
Print minimum possible total instability.
输出最小可能的总不稳定性。
输入输出样例
输入#1
2 1 2 3 4
输出#1
1
输入#2
4 1 3 4 6 3 4 100 200
输出#2
5
输入解题思路,AI测评打分。不知道怎么写?