#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 5e18
#define nl '\n'
int n;
int ans[300001];
bool func(pair<int,int> a[], int v){
   auto [x, ix] = *min_element(a, a+n-1);
   ans[ix] = max(x+1, v);
   ans[1] = ans[ix] - x;
   if(ans[1] > n) return 0;
   for(int i=0; i<n-1; i++){
      auto [x, ix] = a[i];
      ans[ix] = x + ans[1];
      if(ans[ix] > n) return 0;
   }
   return 1;
}
inline void solve(){
   cin>>n;
   pair<int,int> a[n-1];
   int pre = 0;
   for(int i=0; i<n-1; i++){
      int x;
      cin>>x;
      pre += x;
      a[i] = {pre, i+2};
   }
   auto [x, ix] = *min_element(a, a+n-1);
   if(x+1 >= 2 ? func(a, x+2) : func(a, 2)){
      cout<<-1;
      return;
   }
   func(a, 1);
   for(int i=1; i<=n; i++) cout<<ans[i]<<" ";
}
signed main(){
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);cout.tie(NULL);
   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... |