首页 >
> 详细

B. The Three-Body Problem

Description

In the three-body world, humans in the Earth

are attacked by dual-vector foil, which reduces

the human’s three-dimensional space into a

two-dimensional space. Only Cheng Xin and

few other people have survived. Suppose

Cheng Xin invents a technique, which can bring

humans back into life (but cannot convert the

2D world into 3D), many years later, and long

before the Zeroer decides to reboot the

Universe. Now cities are like lines. People living in one city move on a line, and they have their

own private houses.

One day, people in HK (in the 2D world) plan to build an office building, and staffs working

here need to travel between the office and their own houses. We use 1, 2, …, n to denote each

person, whose house location is xi. The travelling cost of one-unit length is one for all staffs. For

instance, if the staff i is located at xi =1 and the office building is at y=5, the cost for him to go to

work is |1-5|=4. As the natural resources are extremely scarce then, people have to find a

position to build the office such that the total energy consumption, Given the locations of staffs, could you help find the best location to build the office

and calculate the minimum total travelling cost of all staffs? For simplicity, you only need to tell

them the minimum total cost.

Input

The input contains several cases and is terminated by end of line. Each test case contains two

lines, the first line contains one integer n (1≤n≤5000), the number of people. The second line

contains n integers xi (1≤xi≤2

31

-1), indicating the location of staff i. Since you have not learned

sorting algorithms, the given locations are in either descending or ascending order.

Output

For each test case, print the minimum total cost of all agents.

Example

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-23:00
- 微信：codinghelp

- 代写cmpt 214编程、代做programming语言、代写c/C++程序 2020-11-08
- 代写csci 2122课程、代做program编程实验、C++程序语言代写代 2020-11-08
- Fit5032语言编程代做、代写web程序实验、Web、Html程序语言代做 2020-11-08
- Com3503程序编程代做、Java，C++，Python留学生编程代写代写 2020-11-08
- 代写program程序课程、代写c++编程实验、C/C++编程语言代做 代做 2020-11-08
- Data留学生编程代做、代写python程序、Java，C++程序语言代写 2020-11-08
- 代写secj 1023实验编程、Programming程序代做、代写c++语 2020-11-08
- 代写cmpsc 465编程、代做java程序语言、Python，C++编程设 2020-11-07
- 代做mf 703语言编程、代写programming程序、Sql编程语言调试 2020-11-07
- 954246编程设计调试、代做programming程序、C++编程语言代写 2020-11-07
- Pstat 115程序实验代写、R编程语言调试、Data留学生程序代做 代写 2020-11-07
- Com1005课程编程代做、代写python程序、Java，C++程序语言调 2020-11-07
- Tcp留学生程序代写、Java程序设计调试、Java编程语言代写 帮做r语言 2020-11-07
- 代写program语言编程、代做data留学生程序、Python，Java编 2020-11-07
- 代做cosc2666编程、代写programming程序、C/C++程序语言 2020-11-07
- Digital编程设计代写、代做r程序实验、代写r留学生程序 调试matla 2020-11-07
- 代写programming程序实验、R程序语言调试、Data课程编程代做 代 2020-11-07
- Comp104-17B程序代写、代做c++编程实验、C++程序语言调试 帮做 2020-11-07
- Csc8501课程程序代做、C++编程语言调试、代写program编程课程 2020-11-07
- 代写css3留学生程序、代做html、Css编程语言、Data课程程序代做 2020-11-07