forked from PawanJaiswal08/leetcode-solutions
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy patharrayrecovery.cpp
More file actions
66 lines (65 loc) · 1.44 KB
/
arrayrecovery.cpp
File metadata and controls
66 lines (65 loc) · 1.44 KB
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
// shree ganeshay namah
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (3.141592653589)
#define mod 1000000007
#define ll long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int c = 0;
vector<int> a(n);
vector<int> b(n);
int flag = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
b[0] = a[0];
for (int i = 1; i < n; i++)
{
if(a[i]==0){
b[i] = b[i-1] + a[i];
continue;
}
if (b[i-1] - a[i] >= 0)
{
flag = 1;
break;
}
else{
b[i] = a[i] + b[i - 1];
}
}
for (int i = 0; i < n; i++)
{
if (flag == 0)
{
cout << b[i] << " ";
}
else{
cout << "-1";
break;
}
}
cout<<endl;
}
return 0;
}