시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 1024 MB | 20 | 11 | 11 | 73.333% |
Today is the first day of work for Charles the Courier. He has been tasked with delivering N packages where each package has a (not necessarily unique) label number between 1 and N inclusive. At the end of each day, he is required to report a sequence A of N integers A1, . . . , AN where Ai is the label number of the ith delivered package.
A mathematician at heart, Charles decides to use delta encoding to save on memory space and records a sequence D of N − 1 integers D1, . . . , DN−1 instead, where Di = Ai+1 − Ai.
After delivering all the packages, Charles realises that he does not know how to recover A from D. Your task today is to help him, or state that it is not possible to uniquely recover A.
Your program must read from standard input.
The first line contains a single integer N, the total number of packages.
The second line contains N − 1 space-separated integers, D1, . . . , DN−1. Di represents the difference between the label numbers of the (i + 1)th and ith delivered package.
Your program must print to standard output.
If it is possible to uniquely recover A from D, your output should contain N space-separated integers, the sequence A.
Otherwise, your output should contain a single integer on a single line, the integer -1.
5 1 3 -2 1
1 2 5 3 4
We are able to uniquely recover A = [1, 2, 5, 3, 4].
This is consistent with D since:
5 2 2 -3 1
1 3 5 2 3
We are able to uniquely recover A = [1, 3, 5, 2, 3]. Note that label numbers can appear more than once.
2 0
-1
We are unable to uniquely recover A since we could have either A = [1, 1] or A = [2, 2].