A11222 | Kayaking
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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!
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!
输入格式
The first line contains one number $n$ ( $2<=n<=50$ ).
The second line contains $2·n$ integer numbers $w_{1}$ , $w_{2}$ , ..., $w_{2n}$ , where $w_{i}$ is weight of person $i$ ( $1<=w_{i}<=1000$ ).
The second line contains $2·n$ integer numbers $w_{1}$ , $w_{2}$ , ..., $w_{2n}$ , where $w_{i}$ is weight of person $i$ ( $1<=w_{i}<=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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted