#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
inline void solve(){
int n;
cin >> n;
vi d(n - 1);
for(int &i : d){
cin >> i;
}
int mn = INT32_MAX, mx = INT32_MIN, sm = 0;
for(int i = 0; i < n - 1; i++){
sm += d[i];
mn = min(mn, sm);
mx = max(mx, sm);
}
if(mx != n - 1 && abs(mn) != n - 1){
cout << "-1\n";
return;
}
vi a(n);
if(mx == n - 1){
a.front() = 1;
for(int i = 0; i < n - 1; i++){
a[i + 1] = a[i] + d[i];
}
}
else{
a.front() = 5;
for(int i = 0; i < n - 1; i++){
a[i + 1] = a[i] + d[i];
}
}
for(int i = 0; i < n; i++){
if(a[i] > n || a[i] <= 0){
cout << "-1\n";
return;
}
}
for(int &i : a){
cout << i << " ";
}
cout << "\n";
return;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1;
//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... |