B. Maximums
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Alicia has an array, a1,a2,…,ana1,a2,…,an, of non-negative integers. For each 1≤i≤n1≤i≤n, she has found a non-negative integer xi=max(0,a1,…,ai−1)xi=max(0,a1,…,ai−1). Note that for i=1i=1, xi=0xi=0.
For example, if Alicia had the array a={0,1,2,0,3}a={0,1,2,0,3}, then x={0,0,1,2,2}x={0,0,1,2,2}.
Then, she calculated an array, b1,b2,…,bnb1,b2,…,bn: bi=ai−xibi=ai−xi.
For example, if Alicia had the array a={0,1,2,0,3}a={0,1,2,0,3}, b={0−0,1−0,2−1,0−2,3−2}={0,1,1,−2,1}b={0−0,1−0,2−1,0−2,3−2}={0,1,1,−2,1}.
Alicia gives you the values b1,b2,…,bnb1,b2,…,bn and asks you to restore the values a1,a2,…,ana1,a2,…,an. Can you help her solve the problem?
Input
The first line contains one integer nn (3≤n≤2000003≤n≤200000) – the number of elements in Alicia's array.
The next line contains nn integers, b1,b2,…,bnb1,b2,…,bn (−109≤bi≤109−109≤bi≤109).
It is guaranteed that for the given array bb there is a solution a1,a2,…,ana1,a2,…,an, for all elements of which the following is true: 0≤ai≤1090≤ai≤109.
Output
Print nn integers, a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109), such that if you calculate xx according to the statement, b1b1 will be equal to a1−x1a1−x1, b2b2 will be equal to a2−x2a2−x2, ..., and bnbn will be equal to an−xnan−xn.
It is guaranteed that there exists at least one solution for the given tests. It can be shown that the solution is unique.
Examples
input
Copy
5 0 1 1 -2 1output
Copy
0 1 2 0 3input
Copy
3 1000 999999000 -1000000000output
Copy
1000 1000000000 0input
Copy
5 2 1 2 2 3output
Copy
2 3 5 7 10Note
The first test was described in the problem statement.
In the second test, if Alicia had an array a={1000,1000000000,0}a={1000,1000000000,0}, then x={0,1000,1000000000}x={0,1000,1000000000} and b={1000−0,1000000000−1000,0−1000000000}={1000,999999000,−1000000000}b={1000−0,1000000000−1000,0−1000000000}={1000,999999000,−1000000000}.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int x=0;
int y=0;
int t=0;
for(int i=0; i<n; i++)
{
cin>>x;
x+=t;
cout<<x;
if(i!=n-1)
printf(" ");
t=max(t,x);
}
return 0;
}