-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayRecovery.cpp
More file actions
54 lines (53 loc) · 1.11 KB
/
ArrayRecovery.cpp
File metadata and controls
54 lines (53 loc) · 1.11 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
cin.tie(0);cin.sync_with_stdio(0);
cout.tie(0);cout.sync_with_stdio(0);
long long int t = 1;
cin >> t;
while (t--)
{
long long int size;
cin>>size;
vector<long long int> vec(size);
vector<long long int> ans(size);
for(int i=0; i<size; i++)
{
cin>>vec[i];
}
ans[0]=vec[0];
int flag=0;
for(long long int i=1; i<size; i++)
{
long long int res1=ans[i-1]+vec[i];
long long int res2=ans[i-1]-vec[i];
if(res2<0)
{
ans[i]=res1;
}
else if(res1==res2)
{
ans[i]=res1;
}
else
{
flag=1;
}
}
if(flag==1)
{
cout<<-1<<endl;
}
else
{
for(long long int i=0; i<size; i++)
{
cout<<ans[i]<<" ";
}
}
cout<<endl;
}
return 0;
}