UVA-11364 - Parking

  • UVa Online Judge 解題結果請於 Submit 後,參閱 uHunt
  • 如果你有任何建議與指教,歡迎於下方留言一起討論喔!
  • 本題選為「20161220 大學程式能力檢定 CPE」題目。

題意概要

Michael 去逛街的時候會把車停在街上的某處,然後到處去採購,請幫 Michael 決定他應該把車停在何處才能使得逛完後回到車上的移動距離最小。他逛的是一條筆直的大街,街上商店的位置以整數來表示,他把車停在某一位置上後會開始到他想去的店逛,等所有店都逛完了再提著他所採購的所有物品回到他的車上去。


Input

The first line of input gives the number of test cases, . There are two lines for each test case. The first gives the number of stores Michael wants to visit, , and the second gives their integer positions on Long Street, .


Output

Output for each test case a line with the minimal distance Michael must walk given optimal parking.


Sample Input

2
4
24 13 89 37
6
7 30 41 14 39 42

Sample Output

152
70
profile-image
David Lu
Hello, I'm David Lu. I am a graduate student in Department of Computer Science at National Chiao Tung University, Taiwan. I am in the Networking and Sensing Systems (NSS) Lab at NCTU. If you have any question, please feel free to contact with me.
comments powered by Disqus