CF1707B.Difference Array
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n non-negative integers. It is guaranteed that a is sorted from small to large.
For each operation, we generate a new array bi=ai+1−ai for 1≤i<n . Then we sort b from small to large, replace a with b , and decrease n by 1 .
After performing n−1 operations, n becomes 1 . You need to output the only integer in array a (that is to say, you need to output a1 ).
输入格式
The input consists of multiple test cases. The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains one integer n ( 2≤n≤105 ) — the length of the array a .
The second line contains n integers a1,a2,…,an ( 0≤a1≤…≤an≤5⋅105 ) — the array a .
It is guaranteed that the sum of n over all test cases does not exceed 2.5⋅105 , and the sum of an over all test cases does not exceed 5⋅105 .
输出格式
For each test case, output the answer on a new line.
输入输出样例
输入#1
5 3 1 10 100 4 4 8 9 13 5 0 0 0 8 13 6 2 4 8 16 32 64 7 0 0 0 0 0 0 0
输出#1
81 3 1 2 0
说明/提示
To simplify the notes, let sort(a) denote the array you get by sorting a from small to large.
In the first test case, a=[1,10,100] at first. After the first operation, a=sort([10−1,100−10])=[9,90] . After the second operation, a=sort([90−9])=[81] .
In the second test case, a=[4,8,9,13] at first. After the first operation, a=sort([8−4,9−8,13−9])=[1,4,4] . After the second operation, a=sort([4−1,4−4])=[0,3] . After the last operation, a=sort([3−0])=[3] .