Untitled
user_9000366
plain_text
2 months ago
896 B
6
Indexable
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } b[0] = a[0]; bool end = false; for (int i = 1; i < n; i++) { int num1 = a[i] + b[i - 1]; int num2 = -a[i] + b[i - 1]; if (num1 >= 0 && num2 >= 0 && num1 != num2) { cout << -1 << endl; end = true; break; } else { b[i] = num1; } } if (!end) { for (int i = 0; i < n; i++) cout << b[i] << " "; cout << endl; } } return 0; }
Editor is loading...
Leave a Comment