#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define int long long
#define ll long long
#define vc vector<char>
#define vi vector<int>
#define vb vector<bool>
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define pip pair<int, pair<int, int>>
#define multi multiset<int>
#define multp multiset<pi>
#define endl '\n'
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 2e5+5;
const int S = 350;
void solve() {
int n;
cin >> n;
vi d(n-1);
for (int &x : d) cin >> x;
vi prfx(n);
prfx[0] = d[0];
for (int i = 1; i < n-1; i++) prfx[i] = prfx[i-1] + d[i];
auto getPrfx = [&](int l, int r) {
r--;
if (l > r) return 0ll;
int L = 0;
if (l) L = prfx[l-1];
int R = prfx[r];
return R - L;
};
int mx = 0, mn = 0;
for (int i = 1; i < n-1; i++) {
if (getPrfx(0, i) > getPrfx(0, mx)) mx = i;
if (getPrfx(0, i) < getPrfx(0, mn)) mn = i;
}
if (abs(getPrfx(min(mn, mx), max(mx, mn))) != n-1) { cout << -1 << endl; return; }
vi res(n);
for (int i = 0; i < n; i++) {
res[i] = abs(getPrfx(min(mn, i), max(mn, i))) + 1;
cout << res[i] << ' ';
}
}
/*
A_1 - A_0
A_2 - a_1
D_i = A_i+1 - A_i
*/
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
bool test = 0;
int t;
if (!test) t = 1;
else cin >> t;
while (t--) {
solve();
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |