-
Notifications
You must be signed in to change notification settings - Fork 0
/
136_B. Array Recovery.cpp
66 lines (61 loc) · 1.43 KB
/
136_B. Array Recovery.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss string
#define ld long double
#define nl cout << "\n"
#define nn "\n"
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
#define yes cout<<"YES"<<nn
#define no cout<<"NO"<<nn
#define pll pair<ll,ll>
#define For(i,x,n) for(ll i =x;i<n;i++)
#define IN1(x);ll x;cin>>x;
#define IN2(x,y);ll x,y;cin>>x>>y;
#define IN3(x,y,z);ll x,y,z;cin>>x>>y>>z;
#define VIN(v);for(ll i = 0;i<v.size();i++) cin>>v[i];
#define fastio(); ios::sync_with_stdio(false);cin.tie(NULL);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
void solve()
{
IN1(n);
ll x;
vector<ll> d(n),a(n);
for(ll i = 0; i<n; i++)
{
cin>>d[i];
}
bool multi = false;
a[0] = d[0];
ll currAdd,currSub,difSub,difAdd;
for(ll i = 1; i<n; i++)
{
if(d[i]<a[i-1]&&d[i]!=0) { multi = true; break;}
currAdd = a[i-1]+d[i];
a[i] = currAdd;
}
if(multi==true) cout<<"-1"<<nn;
else
{
for(auto it: a)cout<<it<<' ';
cout<<nn;
}
}
int main()
{
fastio();
#ifndef ONLINE_JUDGE
input;
output;
#endif
ll t=1;
cin>>t;
while(t--)
{
solve();
}
printclock
cout.flush();
return 0;
}