File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ using namespace std ;
3+
4+
5+ #define ll long long
6+ #define endl " \n "
7+ #define debug (n ) cout<<(n)<<endl;
8+ const ll INF = 2e18 + 99 ;
9+
10+ int main (){
11+ ios_base::sync_with_stdio (false );
12+ cin.tie (NULL );
13+ int t;
14+ cin>>t;
15+ while (t--){
16+ int n;
17+ cin>>n;
18+ int drr[n];
19+ for (int i = 0 ; i < n; i++){
20+ cin>>drr[i];
21+ }
22+ int arr[n];
23+ int check = 0 ;
24+ arr[0 ] = drr[0 ];
25+ for (int i = 1 ; i < n; i++){
26+ int a = arr[i-1 ] + drr[i];
27+ int b = arr[i-1 ] - drr[i];
28+ if ((a > 0 && b > 0 ) && (a != b)){
29+ cout<<-1 <<endl;
30+ check = 1 ;
31+ break ;
32+ }
33+ else {
34+ if (a > 0 ){
35+ arr[i] = a;
36+ }
37+ else {
38+ arr[i] = b;
39+ }
40+ }
41+ }
42+ if (check){
43+ continue ;
44+ }
45+ else {
46+ for (int i = 0 ; i < n; i++){
47+ cout<<arr[i]<<" " ;
48+ }
49+ cout<<endl;
50+ }
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments