Description

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 wi, 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!

Input

The first line contains one number n (2 ≤ n ≤ 50).

The second line contains 2·n integer numbers w1, w2, ..., w2n, where wi is weight of person i (1 ≤ wi ≤ 1000).

Output

Print minimum possible total instability.

Sample Input

21 2 3 4

Sample Output

1

题解

在长度为$2*n$的数列中挑出两个数,使剩下的数两两配对差值和最小。

如果不挑出,贪心的思想,显然按原数组排序就可以找到。

考虑$n$很小,我们暴力枚举挑出的数,把剩下的排序即可。

I think there is no need to tell you how to solve this problem...

 //It is made by Awson on 2017.9.30
 #include <set>
 #include <map>
 #include <cmath>
 #include <ctime>
 #include <queue>
 #include <stack>
 #include <vector>
 #include <cstdio>
 #include <string>
 #include <cstdlib>
 #include <cstring>
 #include <iostream>
 #include <algorithm>
 #define LL long long
 #define Min(a, b) ((a) < (b) ? (a) : (b))
 #define Max(a, b) ((a) > (b) ? (a) : (b))
 using namespace std;
 void read(int &x) {
   ;
   ); ch = getchar());
   ; isdigit(ch); x = (x<<)+(x<<)+ch-, ch = getchar());
   x *= -*flag;
 }

 ], n;
 ];

 void work() {
   read(n); n <<= ;
   ;
   ; i <= n; i++) read(w[i]);
   ; i < n; i++)
     ; j <= n; j++) {
       ;
       ; k <= n; k++)
     if (k!=i && k!= j) sorted[++top] = w[k];
       sort(sorted+, sorted++top);
       ;
       ; i <= top; i += ) cnt += sorted[i+]-sorted[i];
       ans = Min(ans, cnt);
     }
   printf("%d\n", ans);
 }
 int main() {
   work();
   ;
 }

[Codeforces 863B]Kayaking的更多相关文章

  1. Educational Codeforces Round 29

    A. Quasi-palindrome 题目链接:http://codeforces.com/contest/863/problem/A 题目意思:问一个数可不可以在不上一些前缀0以后变成一个回文数. ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. 极光征文 | 写写文章就能赢 Filco,岂不美滋滋

    由极光社区举办的第二届征文大赛 --「我和极光的那些事儿」又来啦! 在简书平台发布文章并投稿至「我和极光的那些事」专题,只要参与就能 100% 获得京东购物卡,更有机会赢取象征信仰的 Filco 机械 ...

  2. 使用IDEA配置Maven + SpringMVC + Mybatis 【一步一步踩坑详细配置完成】

    PS:初学,想使用Maven配置一个SpringMVC的开发环境,照着网上的各种图文解说,配置了好久都没成功,有些写的不够详细,有些只有写一半,走了不少弯弯绕绕,踩了不少的坑,此文将正确配置成功的步骤 ...

  3. python web——Django架构

    环境:windows/linux/OS 需要的软件:Firefox 浏览器(别的也可以 不过firfox和python的webdriver兼容性好) git版本控制系统(使用前要配置 用户 编辑器可以 ...

  4. 配置 CSV Data Set Config 来参数化新增客户信息操作

    1.首先根据新增客户信息的http请求,来确定需要参数化的变量,选取符合测试需求且经常变化或未来会变化的变量为需要参数化的变量,如本文中的客户端名称(sys_name).描述(description) ...

  5. c语言字符类型作业

    一.PTA实验作业 题目1:7-2 统计一行文本的单词个数 1. 本题PTA提交列表 2. 设计思路 1.定义整形变量i=0,count=0,flag. 2.定义数组str[999] 3.输入str[ ...

  6. 团队第1次作业:Our Team TAH

     Team named TAH    不管一个人多么有才能,但是集体常常比他更聪明和更有力. --奥斯特洛夫斯基     *introduce team and teamate 先说说TAH的含义,是 ...

  7. 201621123068 Week03-面向对象入门

    1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识点组织起来.请使用工具画出本周学习到的知识点及知识点之间的联系.步骤如下: 1.1 写出你 ...

  8. Flask 视图

    写个验证用户登录的装饰器:在调用函数前,先检查session里有没有用户 from functools import wraps from flask import session, abort de ...

  9. Webview之H5页面调用android的图库及文件管理

    h5页面打开图片管理器 一般页面在pc打开文件管理器是用 type="file"的代码,可是这在android的webview是无效的,必须为webview设定WebChromeC ...

  10. bzoj千题计划251:bzoj3672: [Noi2014]购票

    http://www.lydsy.com/JudgeOnline/problem.php?id=3672 法一:线段树维护可持久化单调队列维护凸包 斜率优化DP 设dp[i] 表示i号点到根节点的最少 ...