codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

863B.md (1634B)


      1 Source: https://codeforces.com/problemset/problem/863/B
      2 
      3 B. Kayaking
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 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.
     26 
     27 Help the party to determine minimum possible total instability!
     28 
     29 Input
     30 
     31 The first line contains one number *n* (2 ≤ *n* ≤ 50).
     32 
     33 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).
     34 
     35 Output
     36 
     37 Print minimum possible total instability.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 2  
     45 1 2 3 4
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 1
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 4  
     58 1 3 4 6 3 4 100 200
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 5
     65 ```