#K54167. Restore Array P
Restore Array P
Restore Array P
You are given an array \(c\) of length \(n\). Your task is to restore an array \(p\) such that:
\(p_0 = c_0\) and for every \(i\) from \(1\) to \(n-1\), \(p_i = c_i - \max_{0 \le j < i} c_j\).
For example, if \(n=4\) and \(c = [4,7,8,9]\), then:
- \(p_0 = 4\)
- \(p_1 = 7-4 = 3\)
- \(p_2 = 8-\max(4,7)=8-7 = 1\)
- \(p_3 = 9-\max(4,7,8)=9-8 = 1\)
You should implement a program that reads input from stdin and writes the result to stdout.
inputFormat
The first line of input contains a single integer \(T\) (the number of test cases). The description of the test cases follows.
For each test case:
- The first line contains an integer \(n\) (the number of elements in the array \(c\)).
- The second line contains \(n\) space-separated integers representing the array \(c\).
It is guaranteed that \(n \ge 1\).
outputFormat
For each test case, output a single line containing \(n\) space-separated integers representing the restored array \(p\).
## sample1
4
4 7 8 9
4 3 1 1
</p>