Universal Cup Judging System

Universal Cup

Süre Sınırı: 4 s Bellek Sınırı: 2048 MB Toplam puan: 100 Zorluk: [göster] Hack'lenebilir ✓
İstatistikler

Little Cyan Fish は数直線上にいます。最初、彼は位置 $a_0$ にいて、彼の家は位置 $0$ にあります。

彼は位置 $a_1, a_2, \ldots, a_n$ をこの順番に訪れたいと考えています。彼は数直線上をどちらの方向にも歩くことができます。また、任意のタイミングで、自分の家にテレポートするか、または自分の家を現在位置に移動させることができます。これら 2 つの行動はどちらもコストがかからず、歩いている最中も含めて何度でも行うことができます。

与えられた順番ですべての位置を訪れるために彼が歩く必要のある合計距離の最小値を求めてください。

入力

複数のテストケースがあります。入力の 1 行目には、テストケースの個数を表す 1 つの整数 $T$($1 \le T$)が含まれます。

各テストケースについて、1 行目には訪れる位置の個数を表す 1 つの整数 $n$($1 \le n \le 5 \times 10^5$)が含まれます。2 行目には、初期位置と訪れる各位置を表す $n + 1$ 個の整数 $a_0, a_1, \ldots, a_n$($-10^9 \le a_i \le 10^9$)が含まれます。

すべてのテストケースにわたる $n$ の総和は $5 \times 10^5$ を超えないことが保証されます。

出力

各テストケースについて、Little Cyan Fish が歩く必要のある合計距離の最小値を表す 1 つの整数を 1 行に出力してください。

入出力例

入力 1

4
1
7 0
2
0 10 5
3
0 4 2 0
3
-2 3 -2 3

出力 1

0
10
6
8

注記

1 番目のサンプルテストケースでは、Little Cyan Fish は位置 $0$ にある家にテレポートするため、歩く必要はありません。

2 番目のサンプルテストケースでは、彼は $0$ から $10$ まで歩き、その途中で家を位置 $5$ に移動させます。その後、位置 $5$ にテレポートします。合計距離は $10$ です。

3 番目のサンプルテストケースでは、彼は $0$ から $4$ まで歩き、その途中で家を位置 $2$ に移動させます。その後、$2$ にテレポートし、$0$ まで歩きます。合計距離は $4 + 2 = 6$ です。

4 番目のサンプルテストケースでは、彼は $0$ にテレポートし、$3$ まで歩き、家を $3$ に移動させます。その後、$-2$ まで歩き、$3$ にテレポートします。合計距離は $3 + 5 = 8$ です。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#3007EditorialOpenNew Editorial for Problem #22883AnonymousView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.