NvidiaOA #1
Reconstruct Array from Prefix-Skip Sum
Estimated EasyJudge-ready
Topics (AI-labelled)Bits & Math
pref[i] equals the sum of all elements of the original array except the i-th one. Recover the original array. This site guarantees that an integer solution exists and that N is at least 2; N=1 cannot be determined uniquely, so it is not part of this protocol.
This site uses a standard input/output protocol.
Input
The first line contains N, and the second line contains N values pref. This site uses 2≤N≤100000 and −10⁹≤pref[i]≤10⁹, and an integer solution is guaranteed to exist.
Output
Output N integers in original index order.
Example 1
Input:
3
2 6 4
Output:
4 0 2
Example 2
Input:
3
11 9 8
Output:
3 5 6
Example 3
Input:
2
-3 5
Output:
5 -3
Example notes
Example 1: the total is 6, and the answer is 4, 0, 2. Example 2: the total is 14, and the answer is 3, 5, 6. Example 3: with two elements, each pref is the other element, so the answer is 5, −3.
Editorial
Loading solution…