forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1326B - Maximums.cpp
74 lines (51 loc) · 1.89 KB
/
1326B - Maximums.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Alicia has an array, a1,a2,…,an, of non-negative integers. For each 1=i=n, she has found a non-negative integer xi=max(0,a1,…,ai-1). Note that for i=1, xi=0.
For example, if Alicia had the array a={0,1,2,0,3}, then x={0,0,1,2,2}.
Then, she calculated an array, b1,b2,…,bn: bi=ai-xi.
For example, if Alicia had the array a={0,1,2,0,3}, b={0-0,1-0,2-1,0-2,3-2}={0,1,1,-2,1}.
Alicia gives you the values b1,b2,…,bn and asks you to restore the values a1,a2,…,an. Can you help her solve the problem?
Input
The first line contains one integer n (3=n=200000) – the number of elements in Alicia's array.
The next line contains n integers, b1,b2,…,bn (-109=bi=109).
It is guaranteed that for the given array b there is a solution a1,a2,…,an, for all elements of which the following is true: 0=ai=109.
Output
Print n integers, a1,a2,…,an (0=ai=109), such that if you calculate x according to the statement, b1 will be equal to a1-x1, b2 will be equal to a2-x2, ..., and bn will be equal to an-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
inputCopy
5
0 1 1 -2 1
outputCopy
0 1 2 0 3
inputCopy
3
1000 999999000 -1000000000
outputCopy
1000 1000000000 0
inputCopy
5
2 1 2 2 3
outputCopy
2 3 5 7 10
Note
The first test was described in the problem statement.
In the second test, if Alicia had an array a={1000,1000000000,0}, then x={0,1000,1000000000} and b={1000-0,1000000000-1000,0-1000000000}={1000,999999000,-1000000000}.
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector <int> v(n);
for (auto &x: v) cin >> x;
long long maxi = v[0];
cout << v[0] << " "; // first element will remain same
for (int i = 1; i < n; i++) {
long long next = maxi + v[i];
cout << next << " ";
maxi = max(maxi, next);
}
return 0;
}