#K88742. Reconstruct Weights

    ID: 37376 Type: Default 1000ms 256MiB

Reconstruct Weights

Reconstruct Weights

You are given a series of test cases. Each test case consists of an integer \(N\) and a list of \(N\) integers representing the differences between consecutive coin weights. Assume the initial coin weight is \(0\).

Your task is to reconstruct the entire sequence of coin weights for each test case. The sequence is defined by the recurrence relation:

\(a_0 = 0\) and \(a_i = a_{i-1} + d_i\) for \(1 \leq i \leq N\), where \(d_i\) is the \(i\)-th difference.

For each test case, output the reconstructed sequence of \(N+1\) integers, separated by spaces.

inputFormat

The input begins with a line containing the integer \(T\), the number of test cases.

Each test case consists of two parts:

  • The first line contains an integer \(N\), representing the number of differences.
  • The second line contains \(N\) space-separated integers, \(d_1, d_2, \dots, d_N\), which are the differences between consecutive weights.

outputFormat

For each test case, output a single line containing \(N+1\) integers: the reconstructed coin weights starting from \(0\), with each number separated by a space.

## sample
2
2
1 -2
3
3 -1 2
0 1 -1

0 3 2 4

</p>