首页 >
> 详细

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
- 微信：codinghelp2

- Cs2461-10实验程序代做、代写java，C/C++，Python编程设 2021-03-02
- 代写program程序语言、代做python，C++课程程序、代写java编 2021-03-02
- Programming课程代做、代写c++程序语言、Algorithms编程 2021-03-02
- 代写csc1-Ua程序、代做java编程设计、Java实验编程代做 代做留学 2021-03-02
- 代做program编程语言、代写python程序、代做python设计编程 2021-03-02
- 代写data编程设计、代做python语言程序、Python课程编程代写 代 2021-03-02
- Cse 13S程序实验代做、代写c++编程、C/C++程序语言调试 代写留学 2021-03-02
- Mat136h5编程代做、C/C++程序调试、Python，Java编程设计 2021-03-01
- 代写ee425x实验编程、代做python，C++，Java程序设计 帮做c 2021-03-01
- Cscc11程序课程代做、代写python程序设计、Python编程调试 代 2021-03-01
- 代写program编程、Python语言程序调试、Python编程设计代写 2021-03-01
- 代做r语言编程|代做database|代做留学生p... 2021-03-01
- Data Structures代写、代做r编程课程、代做r程序实验 帮做ha 2021-03-01
- 代做data留学生编程、C++，Python语言代写、Java程序代做 代写 2021-03-01
- 代写aps 105编程实验、C/C++程序语言代做 代写r语言程序|代写py 2021-03-01
- Fre6831 Computational Finance 2021-02-28
- Sta141b Assignment 5 Interactive Visu... 2021-02-28
- Eecs2011a-F20 2021-02-28
- Comp-251 Final Asssessment 2021-02-28
- 代写cs1027课程程序、代做java编程语言、代写java留学生编程帮做h 2021-02-28