forked from Vasu1712/Vasu_Hacktober2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Array_Recovery.cpp
More file actions
46 lines (44 loc) · 907 Bytes
/
B_Array_Recovery.cpp
File metadata and controls
46 lines (44 loc) · 907 Bytes
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
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int> nums(n);
for (int i = 0; i < n; i++)
{
cin >> nums[i];
}
vector<int> ans;
ans.push_back(nums[0]);
int prev = nums[0];
int flag = 1;
for (int i = 1; i < n; i++)
{
if (prev - nums[i] >= 0 && nums[i] != 0)
{
flag = 0;
cout << -1 << endl;
break;
}
ans.push_back(nums[i] + prev);
prev = nums[i] + prev;
}
if (flag)
{
for (auto x : ans)
{
cout << x << " ";
}
cout << endl;
}
}
return 0;
}