#P1732. [TJOI2011] 序列

[TJOI2011] 序列

Description

Given a sequence A={a1,a2,,an}A=\{a_1,a_2,\ldots,a_n\}, compute the sequence B={b1,b2,,bn}B=\{b_1,b_2,\ldots,b_n\} from AA, where:

$$b_i= \begin{cases} a_1 &, i=1 \\ \min_{1 \leq j < i}\left|a_i-a_j\right| &, i\gt 1 \end{cases}$$

Find i=1nbi\sum\limits^n_{i=1}b_i.

Input Format

The first line contains a positive integer TT, the number of testdata sets. Then there are TT lines, each describing one set of testdata. Each line starts with a positive integer nn, the number of elements in sequence AA; then follow nn non-negative integers, which are a1,a2,,ana_1,a_2,\ldots,a_n in order.

Output Format

For each testdata set, output the sum of all elements of sequence BB.

2
5 1 2 3 4 5
7 2 9 7 4 6 2 6

5
14

Hint

Constraints: 1t101\le t\le 10, 1n1051\le n\le10^5, 0ai655360\le a_i\le65536.

Translated by ChatGPT 5